ZQuest Classic Coverage Report


Directory: src/
File: src/zc/script_drawing.cpp
Date: 2025-08-12 08:54:40
Exec Total Coverage
Lines: 1450 5752 25.2%
Functions: 55 110 50.0%
Branches: 618 2951 20.9%

Line Branch Exec Source
1 //! ritate_sprite_trans doesn't seem to be supported by or allegro header !?
2
3 //glibc 2.28 and later require this: -Z
4 #include <optional>
5 #include <utility>
6 #ifdef __GNUG__
7 #define ALLEGRO_NO_FIX_ALIASES
8 #endif
9
10 #include "base/qrs.h"
11 #include "base/dmap.h"
12 #include "base/zdefs.h"
13 #include "base/zc_alleg.h"
14 #include "zc/script_drawing.h"
15 #include "zc/rendertarget.h"
16 #include "zc/maps.h"
17 #include "tiles.h"
18 #include "zc/zelda.h"
19 #include "zc/ffscript.h"
20 #include "base/util.h"
21 #include "subscr.h"
22 #include "drawing.h"
23 #include "base/mapscr.h"
24 #include "base/misctypes.h"
25 using namespace util;
26 extern refInfo *ri;
27 extern script_bitmaps scb;
28 #include <stdio.h>
29 #include <fstream>
30
31 #define DegtoFix(d) ((d)*0.7111111111111)
32 #define RadtoFix(d) ((d)*40.743665431525)
33
34 static int32_t secondary_draw_origin_xoff;
35 static int32_t secondary_draw_origin_yoff;
36
37 100455705 static std::optional<std::pair<int, int>> get_draw_origin_offset(DrawOrigin draw_origin, int draw_origin_target_uid, int xoff, int yoff)
38 {
39 int xoffset;
40 int yoffset;
41
2/2
✓ Branch 0 taken 40476 times.
✓ Branch 1 taken 100415229 times.
100455705 if (draw_origin == DrawOrigin::Region)
42 {
43 40476 xoffset = xoff - viewport.x;
44 40476 yoffset = yoff - viewport.y;
45 40476 }
46
2/2
✓ Branch 0 taken 8072 times.
✓ Branch 1 taken 100407157 times.
100415229 else if (draw_origin == DrawOrigin::RegionScrollingNew)
47 {
48 8072 xoffset = xoff + FFCore.ScrollingData[SCROLLDATA_NRX];
49 8072 yoffset = yoff + FFCore.ScrollingData[SCROLLDATA_NRY];
50 8072 }
51
2/2
✓ Branch 0 taken 93964675 times.
✓ Branch 1 taken 6442482 times.
100407157 else if (draw_origin == DrawOrigin::PlayingField)
52 {
53 93964675 xoffset = xoff;
54 93964675 yoffset = yoff;
55 93964675 }
56
2/2
✓ Branch 0 taken 6437172 times.
✓ Branch 1 taken 5310 times.
6442482 else if (draw_origin == DrawOrigin::Screen)
57 {
58 6437172 xoffset = 0;
59 6437172 yoffset = 0;
60 6437172 }
61
1/2
✓ Branch 0 taken 5310 times.
✗ Branch 1 not taken.
5310 else if (draw_origin == DrawOrigin::Sprite)
62 {
63 5310 sprite* draw_origin_target = sprite::getByUID(draw_origin_target_uid);
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5310 times.
5310 if (!draw_origin_target)
65 {
66 Z_scripterrlog("Warning: Ignoring draw command using DRAW_ORIGIN_SPRITE with non-existent sprite uid: %d.\n", draw_origin_target_uid);
67 return std::nullopt;
68 }
69
70 5310 xoffset = xoff - viewport.x + draw_origin_target->x.getInt();
71 5310 yoffset = yoff - viewport.y + draw_origin_target->y.getInt();
72 5310 }
73 else
74 {
75 // Unexpected.
76 xoffset = 0;
77 yoffset = 0;
78 }
79
80 100455705 return std::make_pair(xoffset, yoffset);
81 100455705 }
82
83 380878 std::pair<int, bool> resolveScriptingBitmapId(int scripting_bitmap_id)
84 {
85
2/2
✓ Branch 0 taken 287889 times.
✓ Branch 1 taken 92989 times.
380878 if (scripting_bitmap_id < 0)
86 {
87 // Handles zscript values for RT_SCREEN, etc.
88 92989 return {scripting_bitmap_id / 10000, false};
89 }
90
3/4
✓ Branch 0 taken 287889 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 780 times.
✓ Branch 3 taken 287109 times.
287889 else if (scripting_bitmap_id - 10 >= -2 && scripting_bitmap_id - 10 <= rtBMP6)
91 {
92 // Handles Game->LoadBitmapID, which sets the bitmap pointer as a "long" int.
93 780 return {scripting_bitmap_id - 10, false};
94 }
95 else
96 {
97 // This is a user bitmap.
98 287109 return {scripting_bitmap_id, true};
99 }
100 380878 }
101
102 static BITMAP* current_target_bmp;
103
104 53694974 static BITMAP* resolveScriptingBitmap(int scripting_bitmap_id)
105 {
106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 53694974 times.
53694974 if (scripting_bitmap_id < 0)
107 {
108 // Handles zscript values for RT_SCREEN, etc.
109 return FFCore.GetScriptBitmap((scripting_bitmap_id / 10000) + 10, current_target_bmp);
110 }
111 else
112 {
113 // Handles Game->LoadBitmapID, which sets the bitmap pointer as a "long" int.
114 // Also handles user bitmaps.
115 53694974 return FFCore.GetScriptBitmap(scripting_bitmap_id, current_target_bmp);
116 }
117 53694974 }
118
119 inline double sd_log2( double n )
120 {
121 // log(n)/log(2) is log2.
122 double v = log( (double)n ) / log( (double)2 );
123 return v;
124 }
125
126 inline bool isPowerOfTwo(int32_t n)
127 {
128 if(n==0)
129 return false;
130
131 return (ceil(sd_log2(n)) == floor(sd_log2(n)));
132 }
133
134
135
136 template<class T> inline
137 255763 fixed degrees_to_fixed(T d)
138 {
139 255763 return ftofix(DegtoFix(d));
140 }
141 template<class T> inline
142 fixed radians_to_fixed(T d)
143 {
144 return ftofix(RadtoFix(d));
145 }
146
147 BITMAP* ScriptDrawingBitmapPool::_parent_bmp = 0;
148
149 class TileHelper
150 {
151 public:
152
153 46094 static void OldPutTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
154 {
155 // Past the end of the tile page?
156
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46094 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46094 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
157 {
158 byte w2=(tile+w)%TILES_PER_ROW;
159 OldPutTile(_Dest, tile, x, y, w-w2, h, color, flip);
160 OldPutTile(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip);
161 return;
162 }
163
164
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 46094 times.
46094 switch(flip)
165 {
166 case 1:
167 for(int32_t j=0; j<h; j++)
168 for(int32_t k=w-1; k>=0; k--)
169 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip);
170
171 break;
172
173 case 2:
174 for(int32_t j=h-1; j>=0; j--)
175 for(int32_t k=0; k<w; k++)
176 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip);
177
178 break;
179
180 case 3:
181 for(int32_t j=h-1; j>=0; j--)
182 for(int32_t k=w-1; k>=0; k--)
183 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip);
184
185 break;
186
187 46094 case 0:
188 default:
189
2/2
✓ Branch 0 taken 181240 times.
✓ Branch 1 taken 46094 times.
227334 for(int32_t j=0; j<h; j++)
190
2/2
✓ Branch 0 taken 1111148 times.
✓ Branch 1 taken 181240 times.
1292388 for(int32_t k=0; k<w; k++)
191 1292388 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip);
192
193 46094 break;
194 }
195 46094 }
196
197 4036845 static void OverTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
198 {
199 4036845 overtileblock16(_Dest,tile,x,y,w,h,color,flip,skiprows);
200 4036845 }
201
202 static void OverTileCloaked(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t flip, byte skiprows=0)
203 {
204 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
205 {
206 byte w2=(tile+w)%TILES_PER_ROW;
207 OverTileCloaked(_Dest, tile, x, y, w-w2, h, flip);
208 OverTileCloaked(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, flip);
209 return;
210 }
211
212 switch(flip)
213 {
214 case 1:
215 for(int32_t j=0; j<h; j++)
216 for(int32_t k=w-1; k>=0; k--)
217 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, flip);
218
219 break;
220
221 case 2:
222 for(int32_t j=h-1; j>=0; j--)
223 for(int32_t k=0; k<w; k++)
224 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, flip);
225
226 break;
227
228 case 3:
229 for(int32_t j=h-1; j>=0; j--)
230 for(int32_t k=w-1; k>=0; k--)
231 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, flip);
232
233 break;
234
235 default:
236 for(int32_t j=0; j<h; j++)
237 for(int32_t k=0; k<w; k++)
238 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, flip);
239
240 break;
241 }
242 }
243
244 288307 static void OverTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
245 {
246
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 288307 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
288307 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
247 {
248 byte w2=(tile+w)%TILES_PER_ROW;
249 OverTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
250 OverTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
251 return;
252 }
253
254
1/4
✓ Branch 0 taken 288307 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
288307 switch(flip)
255 {
256 case 1:
257 for(int32_t j=0; j<h; j++)
258 for(int32_t k=w-1; k>=0; k--)
259 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
260
261 break;
262
263 case 2:
264 for(int32_t j=h-1; j>=0; j--)
265 for(int32_t k=0; k<w; k++)
266 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
267
268 break;
269
270 case 3:
271 for(int32_t j=h-1; j>=0; j--)
272 for(int32_t k=w-1; k>=0; k--)
273 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
274
275 break;
276
277 default:
278
2/2
✓ Branch 0 taken 1671585 times.
✓ Branch 1 taken 288307 times.
1959892 for(int32_t j=0; j<h; j++)
279
2/2
✓ Branch 0 taken 23550646 times.
✓ Branch 1 taken 1671585 times.
25222231 for(int32_t k=0; k<w; k++)
280 25222231 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
281
282 288307 break;
283 }
284 288307 }
285
286 static void PutTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
287 {
288 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
289 {
290 byte w2=(tile+w)%TILES_PER_ROW;
291 PutTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
292 PutTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
293 return;
294 }
295
296 switch(flip)
297 {
298 case 1:
299 for(int32_t j=0; j<h; j++)
300 for(int32_t k=w-1; k>=0; k--)
301 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
302
303 break;
304
305 case 2:
306 for(int32_t j=h-1; j>=0; j--)
307 for(int32_t k=0; k<w; k++)
308 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
309
310 break;
311
312 case 3:
313 for(int32_t j=h-1; j>=0; j--)
314 for(int32_t k=w-1; k>=0; k--)
315 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
316
317 break;
318
319 default:
320 for(int32_t j=0; j<h; j++)
321 for(int32_t k=0; k<w; k++)
322 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
323
324 break;
325 }
326 }
327 };
328
329
330
331
332 2499888 void do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
333 {
334 //sdci[1]=layer
335 //sdci[2]=x
336 //sdci[3]=y
337 //sdci[4]=x2
338 //sdci[5]=y2
339 //sdci[6]=color
340 //sdci[7]=scale factor
341 //sdci[8]=rotation anchor x
342 //sdci[9]=rotation anchor y
343 //sdci[10]=rotation angle
344 //sdci[11]=fill
345 //sdci[12]=opacity
346
1/2
✓ Branch 0 taken 2499888 times.
✗ Branch 1 not taken.
2499888 if(sdci[7]==0) //scale
347 {
348 return;
349 }
350
351 2499888 int32_t x1=sdci[2]/10000;
352 2499888 int32_t y1=sdci[3]/10000;
353 2499888 int32_t x2=sdci[4]/10000;
354 2499888 int32_t y2=sdci[5]/10000;
355
356
1/2
✓ Branch 0 taken 2499888 times.
✗ Branch 1 not taken.
2499888 if(x1>x2)
357 {
358 zc_swap(x1,x2);
359 }
360
361
2/2
✓ Branch 0 taken 2480372 times.
✓ Branch 1 taken 19516 times.
2499888 if(y1>y2)
362 {
363 19516 zc_swap(y1,y2);
364 19516 }
365
366
2/2
✓ Branch 0 taken 2498162 times.
✓ Branch 1 taken 1726 times.
2499888 if(sdci[7] != 10000)
367 {
368 1726 int32_t w=x2-x1+1;
369 1726 int32_t h=y2-y1+1;
370 1726 int32_t w2=(w*sdci[7])/10000;
371 1726 int32_t h2=(h*sdci[7])/10000;
372 1726 x1=x1-((w2-w)/2);
373 1726 x2=x2+((w2-w)/2);
374 1726 y1=y1-((h2-h)/2);
375 1726 y2=y2+((h2-h)/2);
376 1726 }
377
378 2499888 int32_t color=sdci[6]/10000;
379
380
2/2
✓ Branch 0 taken 2463409 times.
✓ Branch 1 taken 36479 times.
2499888 if(sdci[12]/10000<=127) //translucent
381 {
382 36479 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
383 36479 }
384
385
2/2
✓ Branch 0 taken 82060 times.
✓ Branch 1 taken 2417828 times.
2499888 if(sdci[10]==0) //no rotation
386 {
387
2/2
✓ Branch 0 taken 833399 times.
✓ Branch 1 taken 1584429 times.
2417828 if(sdci[11]) //filled
388 {
389 1584429 rectfill(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
390 1584429 }
391 else //outline
392 {
393 833399 rect(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
394 }
395 2417828 }
396 else //rotate
397 {
398 int32_t xy[16];
399 82060 int32_t rx=sdci[8]/10000;
400 82060 int32_t ry=sdci[9]/10000;
401 82060 fixed ra1=itofix(sdci[10]%10000)/10000;
402 82060 fixed ra2=itofix(sdci[10]/10000);
403 82060 fixed ra=ra1+ra2;
404 82060 ra = (ra/360)*256;
405
406 82060 fixed fcosa = fixcos(ra);
407 82060 fixed fsina = fixsin(ra);
408
409 82060 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
410 82060 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
411 82060 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
412 82060 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
413 82060 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
414 82060 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
415 82060 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
416 82060 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
417 82060 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
418 82060 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
419 82060 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
420 82060 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
421 82060 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
422 82060 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
423 82060 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
424 82060 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
425
426
1/2
✓ Branch 0 taken 82060 times.
✗ Branch 1 not taken.
82060 if(sdci[11]) //filled
427 {
428 82060 polygon(bmp, 4, xy, color);
429 82060 }
430 else //outline
431 {
432 line(bmp, xy[0], xy[1], xy[10], xy[11], color);
433 line(bmp, xy[2], xy[3], xy[12], xy[13], color);
434 line(bmp, xy[4], xy[5], xy[14], xy[15], color);
435 line(bmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
436 }
437 }
438
439 2499888 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
440 2499888 }
441
442 void do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
443 {
444 //sdci[1]=layer
445 //sdci[2]=x
446 //sdci[3]=y
447 //sdci[4]=tile
448 //sdci[5]=cset
449 //sdci[6]=width
450 //sdci[7]=height
451 //sdci[8]=overlay
452 //sdci[9]=opacity
453
454 int32_t x=sdci[2]/10000;
455 int32_t y=sdci[3]/10000;
456
457 int32_t tile=sdci[4]/10000;
458 int32_t cs=sdci[5]/10000;
459 int32_t w=sdci[6]/10000;
460 int32_t h=sdci[7]/10000;
461 bool overlay=sdci[8];
462 bool trans=(sdci[9]/10000<=127);
463
464 frame2x2(bmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
465 }
466
467
468
469 1170321 void do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
470 {
471 //sdci[1]=layer
472 //sdci[2]=x
473 //sdci[3]=y
474 //sdci[4]=radius
475 //sdci[5]=color
476 //sdci[6]=scale factor
477 //sdci[7]=rotation anchor x
478 //sdci[8]=rotation anchor y
479 //sdci[9]=rotation angle
480 //sdci[10]=fill
481 //sdci[11]=opacity
482
1/2
✓ Branch 0 taken 1170321 times.
✗ Branch 1 not taken.
1170321 if(sdci[6]==0) //scale
483 {
484 return;
485 }
486
487 1170321 int32_t x1=sdci[2]/10000;
488 1170321 int32_t y1=sdci[3]/10000;
489 1170321 qword r=sdci[4];
490
491
1/2
✓ Branch 0 taken 1170321 times.
✗ Branch 1 not taken.
1170321 if(sdci[6] != 10000)
492 {
493 r*=sdci[6];
494 r/=10000;
495 }
496
497 1170321 r/=10000;
498 1170321 int32_t color=sdci[5]/10000;
499
500
2/2
✓ Branch 0 taken 989014 times.
✓ Branch 1 taken 181307 times.
1170321 if(sdci[11]/10000<=127) //translucent
501 {
502 181307 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
503 181307 }
504
505
5/6
✓ Branch 0 taken 58575 times.
✓ Branch 1 taken 1111746 times.
✓ Branch 2 taken 1344 times.
✓ Branch 3 taken 57231 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1344 times.
1170321 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
506 {
507 int32_t xy[2];
508 57231 int32_t rx=sdci[7]/10000;
509 57231 int32_t ry=sdci[8]/10000;
510 57231 fixed ra1=itofix(sdci[9]%10000)/10000;
511 57231 fixed ra2=itofix(sdci[9]/10000);
512 57231 fixed ra=ra1+ra2;
513 57231 ra = (ra/360)*256;
514
515 57231 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
516 57231 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
517 57231 x1=xy[0];
518 57231 y1=xy[1];
519 57231 }
520
521
2/2
✓ Branch 0 taken 1153307 times.
✓ Branch 1 taken 17014 times.
1170321 if(sdci[10]) //filled
522 {
523 1153307 circlefill(bmp, x1+xoffset, y1+yoffset, r, color);
524 1153307 }
525 else //outline
526 {
527 17014 circle(bmp, x1+xoffset, y1+yoffset, r, color);
528 }
529
530 1170321 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
531 1170321 }
532
533
534 void do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
535 {
536 //sdci[1]=layer
537 //sdci[2]=x
538 //sdci[3]=y
539 //sdci[4]=radius
540 //sdci[5]=start angle
541 //sdci[6]=end angle
542 //sdci[7]=color
543 //sdci[8]=scale factor
544 //sdci[9]=rotation anchor x
545 //sdci[10]=rotation anchor y
546 //sdci[11]=rotation angle
547 //sdci[12]=closed
548 //sdci[13]=fill
549 //sdci[14]=opacity
550
551 if(sdci[8]==0) //scale
552 {
553 return;
554 }
555
556 int32_t cx=sdci[2]/10000;
557 int32_t cy=sdci[3]/10000;
558 qword r=sdci[4];
559
560 if(sdci[8] != 10000)
561 {
562 r*=sdci[8];
563 r/=10000;
564 }
565
566 r/=10000;
567
568 int32_t color=sdci[7]/10000;
569
570 fixed ra1=itofix(sdci[11]%10000)/10000;
571 fixed ra2=itofix(sdci[11]/10000);
572 fixed ra=ra1+ra2;
573 ra = (ra/360)*256;
574
575
576 fixed a1=itofix(sdci[5]%10000)/10000;
577 fixed a2=itofix(sdci[5]/10000);
578 fixed sa=a1+a2;
579 sa = (sa/360)*256;
580
581 a1=itofix(sdci[6]%10000)/10000;
582 a2=itofix(sdci[6]/10000);
583 fixed ea=a1+a2;
584 ea = (ea/360)*256;
585
586 if(sdci[11]!=0) //rotation
587 {
588 int32_t rx=sdci[9]/10000;
589 int32_t ry=sdci[10]/10000;
590
591 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
592 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
593 ea-=ra;
594 sa-=ra;
595 }
596
597 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
598 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
599
600 if(sdci[12]) //closed
601 {
602 if(sdci[13]) //filled
603 {
604 clear_bitmap(prim_bmp);
605 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
606 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
607 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
608 int fillx = zc_max(0,fx)+xoffset;
609 int filly = zc_max(0,fy)+yoffset;
610 zprint2("Screen->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
611 floodfill(prim_bmp, fillx, filly, color);
612
613 if(sdci[14]/10000<=127) //translucent
614 {
615 draw_trans_sprite(bmp, prim_bmp, 0,0);
616 }
617 else
618 {
619 draw_sprite(bmp, prim_bmp, 0,0);
620 }
621 }
622 else
623 {
624 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
625 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
626 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
627 }
628 }
629 else
630 {
631 if(sdci[14]/10000<=127) //translucent
632 {
633 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
634 }
635
636 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
637 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
638 }
639 }
640
641
642 1850 void do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
643 {
644 //sdci[1]=layer
645 //sdci[2]=x
646 //sdci[3]=y
647 //sdci[4]=radiusx
648 //sdci[5]=radiusy
649 //sdci[6]=color
650 //sdci[7]=scale factor
651 //sdci[8]=rotation anchor x
652 //sdci[9]=rotation anchor y
653 //sdci[10]=rotation angle
654 //sdci[11]=fill
655 //sdci[12]=opacity
656
657
1/2
✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
1850 if(sdci[7]==0) //scale
658 {
659 return;
660 }
661
662 1850 int32_t x1=sdci[2]/10000;
663 1850 int32_t y1=sdci[3]/10000;
664 1850 int32_t radx=sdci[4]/10000;
665 1850 radx*=sdci[7]/10000;
666 1850 int32_t rady=sdci[5]/10000;
667 1850 rady*=sdci[7]/10000;
668 1850 int32_t color=sdci[6]/10000;
669 1850 float rotation = sdci[10]/10000;
670
671 1850 int32_t rx=sdci[8]/10000;
672 1850 int32_t ry=sdci[9]/10000;
673 1850 fixed ra1=itofix(sdci[10]%10000)/10000;
674 1850 fixed ra2=itofix(sdci[10]/10000);
675 1850 fixed ra=ra1+ra2;
676 1850 ra = (ra/360)*256;
677
678 int32_t xy[2];
679 1850 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
680 1850 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
681 1850 x1=xy[0];
682 1850 y1=xy[1];
683
684
6/8
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 1687 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 1687 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1687 times.
1850 if(radx<1||rady<1||radx>255||rady>255) return;
685
686 1687 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
687
688
2/2
✓ Branch 0 taken 1630 times.
✓ Branch 1 taken 57 times.
1687 if(sdci[11]) //filled
689 {
690
691
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 606 times.
1630 if(sdci[12]/10000<128) //translucent
692 {
693 1024 clear_bitmap(prim_bmp);
694
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
695 1024 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
696 1024 draw_trans_sprite(bmp, prim_bmp, 0, 0);
697 1024 }
698 else // no opacity
699 {
700
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
701 606 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
702 }
703 1630 }
704 else //not filled
705 {
706
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 43 times.
57 if(sdci[12]/10000<128) //translucent
707 {
708 14 clear_bitmap(prim_bmp);
709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
710 14 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
711 14 draw_trans_sprite(bmp, prim_bmp, 0, 0);
712 14 }
713 else // no opacity
714 {
715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
716 43 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
717 }
718 }
719
720 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
721 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
722 // the ellipse, but it shouldn't be used anyway.
723
1/2
✓ Branch 0 taken 1687 times.
✗ Branch 1 not taken.
1687 if(color==0)
724 {
725 // This is very slow, so check the smallest possible square
726 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
727 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
728
729 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
730 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
731 if(getpixel(bmp, x, y)==255)
732 putpixel(bmp, x, y, 0);
733 }
734
735 1687 script_drawing_commands.ReleaseSubBitmap(bitty);
736 1850 }
737
738
739 2351475 void do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
740 {
741 //sdci[1]=layer
742 //sdci[2]=x
743 //sdci[3]=y
744 //sdci[4]=x2
745 //sdci[5]=y2
746 //sdci[6]=color
747 //sdci[7]=scale factor
748 //sdci[8]=rotation anchor x
749 //sdci[9]=rotation anchor y
750 //sdci[10]=rotation angle
751 //sdci[11]=opacity
752
1/2
✓ Branch 0 taken 2351475 times.
✗ Branch 1 not taken.
2351475 if(sdci[7]==0) //scale
753 {
754 return;
755 }
756
757 2351475 int32_t x1=sdci[2]/10000;
758 2351475 int32_t y1=sdci[3]/10000;
759 2351475 int32_t x2=sdci[4]/10000;
760 2351475 int32_t y2=sdci[5]/10000;
761
762
2/2
✓ Branch 0 taken 1903153 times.
✓ Branch 1 taken 448322 times.
2351475 if(sdci[7] != 10000)
763 {
764 448322 int32_t w=x2-x1+1;
765 448322 int32_t h=y2-y1+1;
766 448322 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
767 448322 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
768 448322 x1=x1-((w2-w)/2);
769 448322 x2=x2+((w2-w)/2);
770 448322 y1=y1-((h2-h)/2);
771 448322 y2=y2+((h2-h)/2);
772 448322 }
773
774 2351475 int32_t color=sdci[6]/10000;
775
776
1/2
✓ Branch 0 taken 2351475 times.
✗ Branch 1 not taken.
2351475 if(sdci[11]/10000<=127) //translucent
777 {
778 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
779 }
780
781
2/2
✓ Branch 0 taken 939459 times.
✓ Branch 1 taken 1412016 times.
2351475 if(sdci[10]!=0) //rotation
782 {
783 int32_t xy[4];
784 1412016 int32_t rx=sdci[8]/10000;
785 1412016 int32_t ry=sdci[9]/10000;
786 1412016 fixed ra1=itofix(sdci[10]%10000)/10000;
787 1412016 fixed ra2=itofix(sdci[10]/10000);
788 1412016 fixed ra=ra1+ra2;
789
790 1412016 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
791 1412016 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
792 1412016 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
793 1412016 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
794 1412016 x1=xy[0];
795 1412016 y1=xy[1];
796 1412016 x2=xy[2];
797 1412016 y2=xy[3];
798 1412016 }
799
800 2351475 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
801 2351475 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
802 2351475 }
803
804 void do_linesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
805 {
806 //sdci[1]=layer
807 //sdci[2]=array[10] = { x, y, x2, y2, colour, scale, rx, ry, angle, opacity }
808
809 //sdci[2]=x
810 //sdci[3]=y
811 //sdci[4]=x2
812 //sdci[5]=y2
813 //sdci[6]=color
814 //sdci[7]=scale factor
815 //sdci[8]=rotation anchor x
816 //sdci[9]=rotation anchor y
817 //sdci[10]=rotation angle
818 //sdci[11]=opacity
819 //if(sdci[7]==0) //scale
820 //{
821 // return;
822 //}
823
824 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
825
826 if(!v_ptr)
827 {
828 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
829 return;
830 }
831
832 std::vector<int32_t> &v = *v_ptr;
833
834 if(v.empty())
835 return;
836
837 int32_t* pos = &v[0];
838 int32_t sz = v.size();
839
840 for ( int32_t q = 0; q < sz; q+=10 )
841 {
842
843 int32_t x1 = v.at(q);
844 //Z_scripterrlog("Lines( x1 ) is: %d\n", x1);
845 int32_t y1 = v.at(q+1);
846 //Z_scripterrlog("Lines( x2 ) is: %d\n", y1);
847 int32_t x2 = v.at(q+2);
848 //Z_scripterrlog("Lines( x2 ) is: %d\n", x2);
849 int32_t y2 = v.at(q+3);
850 //Z_scripterrlog("Lines( y2 ) is: %d\n", y2);
851 int32_t color = v.at(q+4);
852 //Z_scripterrlog("Lines( colour ) is: %d\n", color);
853 //Z_scripterrlog("Lines( scale ) is: %d\n", v.at(q+5));
854 if (v.at(q+5) == 0) { Z_scripterrlog("Lines() aborting due to scale\n"); return; }//scale
855
856 if( v.at(q+5) != 10000)
857 {
858 int32_t w=x2-x1+1;
859 int32_t h=y2-y1+1;
860 int32_t w2=int32_t(w*((double)v.at(q+5)));
861 int32_t h2=int32_t(h*((double)v.at(q+5)));
862 x1=x1-((w2-w)/2);
863 x2=x2+((w2-w)/2);
864 y1=y1-((h2-h)/2);
865 y2=y2+((h2-h)/2);
866 }
867
868
869 //Z_scripterrlog("Lines( opacity ) is: %d\n", v.at(q+9));
870 if(v.at(q+9) <= 127) //translucent
871 {
872 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
873 }
874 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
875 //Z_scripterrlog("Lines( rotation ) is: %d\n", v.at(q+8));
876 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+6));
877 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+7));
878 if( v.at(q+8) !=0 ) //rotation
879 {
880 int32_t xy[4];
881
882 int32_t rx = v.at(q+6);
883
884 int32_t ry = v.at(q+7);
885
886 fixed ra1=itofix(v.at(q+8) % 1);
887 fixed ra2=itofix(v.at(q+8));
888 fixed ra=ra1+ra2;
889
890 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
891 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
892 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
893 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
894 x1=xy[0];
895 y1=xy[1];
896 x2=xy[2];
897 y2=xy[3];
898 }
899 //Z_scripterrlog("Lines( xofs ) is: %d\n", xoffset);
900 //Z_scripterrlog("Lines( yofs ) is: %d\n", yoffset);
901 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
902 }
903 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
904 }
905
906 1080 void do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
907 {
908 //sdci[1]=layer
909 //sdci[2]=point count
910 //sdci[3]array[]
911 //sdci[4] = colour
912 //sdci[5] = opacity
913
914 1080 int32_t col = sdci[4]/10000;
915 1080 int32_t op = sdci[5]/10000;
916
917 1080 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
918
919
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(!v_ptr)
920 {
921 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
922 return;
923 }
924
925 1080 std::vector<int32_t> &v = *v_ptr;
926
927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1080 times.
1080 if(v.empty())
928 return;
929
930 1080 int32_t* pos = &v[0];
931 1080 int32_t sz = v.size();
932 1080 int32_t numpoints = (sdci[2]/10000);
933
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(sz & 1) --sz; //even amount only
934
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(numpoints > sz/2) //cap to array
935 numpoints = sz/2;
936
1/2
✓ Branch 0 taken 1080 times.
✗ Branch 1 not taken.
1080 if(numpoints < 1)
937 return; //Don't draw 0 or negative point count
938
939
2/2
✓ Branch 0 taken 6480 times.
✓ Branch 1 taken 1080 times.
7560 for (int32_t i = 0; i < sz; i += 2)
940 {
941 6480 pos[i] += xoffset;
942 6480 pos[i + 1] += yoffset;
943 6480 }
944
945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1080 times.
1080 if(op <= 127) //translucent
946 {
947 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
948 }
949 1080 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
950
951 1080 polygon(bmp, numpoints, (int32_t*)pos, col);
952 1080 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
953 1080 }
954
955 void bmp_do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
956 {
957 //sdci[1]=layer
958 //sdci[2]=point count
959 //sdci[3]array[]
960 //sdci[4] = colour
961 //sdci[5] = opacity
962
963 int32_t col = sdci[4]/10000;
964 int32_t op = sdci[5]/10000;
965
966 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
967 {
968 Z_scripterrlog("bitmap->Polygon() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
969 return;
970 }
971 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
972 if ( refbmp == NULL ) return;
973
974 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
975
976 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
977
978 if(!v_ptr)
979 {
980 al_trace("bitmap->Polygon: Vector pointer is null! Internal error. \n");
981 return;
982 }
983
984 std::vector<int32_t> &v = *v_ptr;
985
986 if(v.empty())
987 return;
988
989 int32_t* pos = &v[0];
990 int32_t sz = v.size();
991 int32_t numpoints = (sdci[2]/10000);
992 if(sz & 1) --sz; //even amount only
993 if(numpoints > sz/2) //cap to array
994 numpoints = sz/2;
995 if(numpoints < 1)
996 return; //Don't draw 0 or negative point count
997
998 for (int32_t i = 0; i < sz; i += 2)
999 {
1000 pos[i] += xoffset;
1001 pos[i + 1] += yoffset;
1002 }
1003
1004 if(op <= 127) //translucent
1005 {
1006 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1007 }
1008 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1009
1010 polygon(refbmp, numpoints, (int32_t*)pos, col);
1011 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1012 }
1013
1014 void do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1015 {
1016 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
1017
1018 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
1019 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
1020 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
1021 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
1022 };
1023
1024 if(sdci[11]/10000 < 128) //translucent
1025 {
1026 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1027 }
1028
1029 spline(bmp, points, sdci[10]/10000);
1030
1031 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1032 }
1033
1034
1035 404879 void do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1036 {
1037 //sdci[1]=layer
1038 //sdci[2]=x
1039 //sdci[3]=y
1040 //sdci[4]=color
1041 //sdci[5]=rotation anchor x
1042 //sdci[6]=rotation anchor y
1043 //sdci[7]=rotation angle
1044 //sdci[8]=opacity
1045 404879 int32_t x1=sdci[2]/10000;
1046 404879 int32_t y1=sdci[3]/10000;
1047 404879 int32_t color=sdci[4]/10000;
1048
1049
2/2
✓ Branch 0 taken 404863 times.
✓ Branch 1 taken 16 times.
404879 if(sdci[8]/10000<=127) //translucent
1050 {
1051 16 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1052 16 }
1053
1054
1/2
✓ Branch 0 taken 404879 times.
✗ Branch 1 not taken.
404879 if(sdci[7]!=0) //rotation
1055 {
1056 int32_t xy[2];
1057 int32_t rx=sdci[5]/10000;
1058 int32_t ry=sdci[6]/10000;
1059 fixed ra1=itofix(sdci[7]%10000)/10000;
1060 fixed ra2=itofix(sdci[7]/10000);
1061 fixed ra=ra1+ra2;
1062
1063 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1064 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1065 x1=xy[0];
1066 y1=xy[1];
1067 }
1068
1069 404879 putpixel(bmp, x1+xoffset, y1+yoffset, color);
1070 404879 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1071 404879 }
1072
1073 void do_putpixelsr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1074 {
1075 //Z_scripterrlog("Starting putpixels()%s\n");
1076 //sdci[1]=layer
1077 //sdci[2]=array {x,y,colour,opacity}
1078 //sdci[3]=rotation anchor x
1079 //sdci[4]=rotation anchor y
1080 //sdci[5]=rotation angle
1081
1082
1083 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1084
1085 if(!v_ptr)
1086 {
1087 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1088 return;
1089 }
1090
1091 std::vector<int32_t> &v = *v_ptr;
1092
1093 if(v.empty())
1094 return;
1095
1096 int32_t* pos = &v[0];
1097 int32_t sz = v.size();
1098
1099
1100 int32_t x1 = 0;
1101 int32_t y1 = 0;
1102
1103 for ( int32_t q = 0; q < sz; q+=4 )
1104 {
1105 x1 = v.at(q); //pos[q];
1106 y1 = v.at(q+1); //pos[q+1];
1107 if(sdci[5]!=0) //rotation
1108 {
1109 int32_t xy[2];
1110 int32_t rx=sdci[3]/10000;
1111 int32_t ry=sdci[4]/10000;
1112 fixed ra1=itofix(sdci[5]%10000)/10000;
1113 fixed ra2=itofix(sdci[5]/10000);
1114 fixed ra=ra1+ra2;
1115
1116 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1117 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1118 x1=xy[0];
1119 y1=xy[1];
1120 }
1121 if ( v.at(q+3) /*pos[q+3]*/ < 128 ) drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1122 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1123 putpixel(bmp, x1+xoffset, y1+yoffset, v.at(q+2) /*pos[q+2]*/);
1124 }
1125 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1126 }
1127
1128 1576950 void do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1129 {
1130 //sdci[1]=layer
1131 //sdci[2]=x
1132 //sdci[3]=y
1133 //sdci[4]=tile
1134 //sdci[5]=tile width
1135 //sdci[6]=tile height
1136 //sdci[7]=color (cset)
1137 //sdci[8]=scale x
1138 //sdci[9]=scale y
1139 //sdci[10]=rotation anchor x
1140 //sdci[11]=rotation anchor y
1141 //sdci[12]=rotation angle
1142 //sdci[13]=flip
1143 //sdci[14]=transparency
1144 //sdci[15]=opacity
1145
1146 1576950 int32_t w = sdci[5]/10000;
1147 1576950 int32_t h = sdci[6]/10000;
1148
1149
4/8
✓ Branch 0 taken 1576950 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1576950 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1576950 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1576950 times.
1576950 if(w < 1 || h < 1 || h > 20 || w > 20)
1150 {
1151 return;
1152 }
1153
1154 1576950 int32_t xscale=sdci[8]/10000;
1155 1576950 int32_t yscale=sdci[9]/10000;
1156 1576950 int32_t rx = sdci[10]/10000;
1157 1576950 int32_t ry = sdci[11]/10000;
1158 1576950 float rotation=sdci[12]/10000;
1159 1576950 int32_t flip=(sdci[13]/10000)&3;
1160 1576950 bool transparency=sdci[14]!=0;
1161 1576950 int32_t opacity=sdci[15]/10000;
1162 1576950 int32_t color=sdci[7]/10000;
1163
1164 1576950 int32_t x1=sdci[2]/10000;
1165 1576950 int32_t y1=sdci[3]/10000;
1166
1167 //don't scale if it's not safe to do so
1168 1576950 bool canscale = true;
1169
1170
3/4
✓ Branch 0 taken 1556305 times.
✓ Branch 1 taken 20645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1556305 times.
1576950 if(xscale==0||yscale==0)
1171 {
1172 20645 return;
1173 }
1174
1175
3/4
✓ Branch 0 taken 140477 times.
✓ Branch 1 taken 1415828 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 140477 times.
1556305 if(xscale<=0||yscale<=0)
1176 1415828 canscale = false; //default size
1177
1178
4/4
✓ Branch 0 taken 140477 times.
✓ Branch 1 taken 1415828 times.
✓ Branch 2 taken 140517 times.
✓ Branch 3 taken 1275311 times.
1556305 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1179 {
1180 280994 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
1181
1182
1/2
✓ Branch 0 taken 280994 times.
✗ Branch 1 not taken.
280994 if(transparency) //transparency
1183 {
1184 280994 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1185 280994 }
1186 else //no transparency
1187 {
1188 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1189 }
1190
1191
2/2
✓ Branch 0 taken 144205 times.
✓ Branch 1 taken 136789 times.
280994 if(rotation != 0)
1192 {
1193 //low negative values indicate no anchor-point rotation
1194
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 144205 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
144205 if(rx>-777||ry>-777)
1195 {
1196 int32_t xy[2];
1197 144205 fixed ra1=itofix(sdci[12]%10000)/10000;
1198 144205 fixed ra2=itofix(sdci[12]/10000);
1199 144205 fixed ra=ra1+ra2;
1200 144205 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1201 144205 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1202 144205 x1=xy[0];
1203 144205 y1=xy[1];
1204 144205 }
1205
1206
2/2
✓ Branch 0 taken 3688 times.
✓ Branch 1 taken 140517 times.
144205 if(canscale) //scale first
1207 {
1208 //damnit all, .. fixme.
1209
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3688 times.
3688 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1210 3688 clear_bitmap(tempbit);
1211
1212 3688 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1213
1214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
3688 if(opacity < 128)
1215 {
1216 clear_bitmap(prim_bmp);
1217 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1218 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1219 }
1220 else
1221 {
1222 3688 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1223 }
1224
1225 3688 destroy_bitmap(tempbit);
1226 3688 }
1227 else //no scale
1228 {
1229
2/2
✓ Branch 0 taken 3586 times.
✓ Branch 1 taken 136931 times.
140517 if(opacity < 128)
1230 {
1231 3586 clear_bitmap(prim_bmp);
1232 3586 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1233 3586 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1234 3586 }
1235 else
1236 {
1237 136931 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1238 }
1239 }
1240 144205 }
1241 else //scale only
1242 {
1243
1/2
✓ Branch 0 taken 136789 times.
✗ Branch 1 not taken.
136789 if(canscale)
1244 {
1245
2/2
✓ Branch 0 taken 4344 times.
✓ Branch 1 taken 132445 times.
136789 if(opacity<128)
1246 {
1247 4344 clear_bitmap(prim_bmp);
1248 4344 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1249 4344 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1250 4344 }
1251 else
1252 {
1253 132445 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1254 }
1255 136789 }
1256 else //error -do not scale
1257 {
1258 if(opacity<128)
1259 {
1260 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1261 }
1262 else
1263 {
1264 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1265 }
1266 }
1267 }
1268
1269 280994 script_drawing_commands.ReleaseSubBitmap(pbitty);
1270
1271 280994 }
1272 else // no scale or rotation
1273 {
1274
2/2
✓ Branch 0 taken 1247857 times.
✓ Branch 1 taken 27454 times.
1275311 if(transparency)
1275 {
1276
2/2
✓ Branch 0 taken 224767 times.
✓ Branch 1 taken 1023090 times.
1247857 if(opacity<=127)
1277 224767 TileHelper::OverTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1278 else
1279 1023090 TileHelper::OverTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1280 1247857 }
1281 else
1282 {
1283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27454 times.
27454 if(opacity<=127)
1284 TileHelper::PutTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1285 else
1286 27454 TileHelper::OldPutTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1287 }
1288 }
1289 1576950 }
1290
1291 void do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1292 {
1293 //sdci[1]=layer
1294 //sdci[2]=x
1295 //sdci[3]=y
1296 //sdci[4]=tile
1297 //sdci[5]=tile width
1298 //sdci[6]=tile height
1299 //sdci[7]=flip
1300
1301 int32_t w = sdci[5]/10000;
1302 int32_t h = sdci[6]/10000;
1303
1304 if(w < 1 || h < 1 || h > 20 || w > 20)
1305 {
1306 return;
1307 }
1308
1309 int32_t flip=(sdci[7]/10000)&3;
1310
1311 int32_t x1=sdci[2]/10000;
1312 int32_t y1=sdci[3]/10000;
1313
1314 TileHelper::OverTileCloaked(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
1315 }
1316
1317
1318 2745108 void do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1319 {
1320 //sdci[1]=layer
1321 //sdci[2]=x
1322 //sdci[3]=y
1323 //sdci[4]=combo
1324 //sdci[5]=tile width
1325 //sdci[6]=tile height
1326 //sdci[7]=color (cset)
1327 //sdci[8]=scale x
1328 //sdci[9]=scale y
1329 //sdci[10]=rotation anchor x
1330 //sdci[11]=rotation anchor y
1331 //sdci[12]=rotation angle
1332 //sdci[13]=frame
1333 //sdci[14]=flip
1334 //sdci[15]=transparency
1335 //sdci[16]=opacity
1336
1337 2745108 int32_t w = sdci[5]/10000;
1338 2745108 int32_t h = sdci[6]/10000;
1339
1340
4/8
✓ Branch 0 taken 2745108 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2745108 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2745108 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2745108 times.
2745108 if(w<1||h<1||h>20||w>20)
1341 {
1342 return;
1343 }
1344 2745108 int32_t cmb = (sdci[4]/10000);
1345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2745108 times.
2745108 if((unsigned)cmb >= MAXCOMBOS)
1346 {
1347 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1348 return;
1349 }
1350
1351 2745108 int32_t xscale=sdci[8]/10000;
1352 2745108 int32_t yscale=sdci[9]/10000;
1353 2745108 int32_t rx = sdci[10]/10000; //these work now
1354 2745108 int32_t ry = sdci[11]/10000; //these work now
1355 2745108 float rotation=sdci[12]/10000;
1356
1357 2745108 bool transparency=sdci[15]!=0;
1358 2745108 int32_t opacity=sdci[16]/10000;
1359 2745108 int32_t color=sdci[7]/10000;
1360 2745108 int32_t x1=sdci[2]/10000;
1361 2745108 int32_t y1=sdci[3]/10000;
1362
1363 2745108 auto& c = GET_DRAWING_COMBO(cmb);
1364
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2745108 times.
2745108 if(c.animflags & AF_EDITOR_ONLY) return;
1365 2745108 int32_t tiletodraw = combo_tile(c, x1, y1);
1366 2745108 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
1367 2745108 int32_t skiprows=c.skipanimy;
1368
1369
1370 //don't scale if it's not safe to do so
1371 2745108 bool canscale = true;
1372
1373
3/4
✓ Branch 0 taken 2745035 times.
✓ Branch 1 taken 73 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2745035 times.
2745108 if(xscale==0||yscale==0)
1374 {
1375 73 return;
1376 }
1377
1378
3/4
✓ Branch 0 taken 23422 times.
✓ Branch 1 taken 2721613 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 23422 times.
2745035 if(xscale<=0||yscale<=0)
1379 2721613 canscale = false; //default size
1380
1381
4/4
✓ Branch 0 taken 23422 times.
✓ Branch 1 taken 2721613 times.
✓ Branch 2 taken 102972 times.
✓ Branch 3 taken 2618641 times.
2745035 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1382 {
1383 126394 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
1384
1385
2/2
✓ Branch 0 taken 125358 times.
✓ Branch 1 taken 1036 times.
126394 if(transparency)
1386 {
1387 125358 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1388 125358 }
1389 else //no transparency
1390 {
1391 1036 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1392 }
1393
1394
2/2
✓ Branch 0 taken 103190 times.
✓ Branch 1 taken 23204 times.
126394 if(rotation != 0) // rotate
1395 {
1396 //fixed point sucks ;0
1397
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 103190 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
103190 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
1398 {
1399 int32_t xy[2];
1400 103190 fixed ra1=itofix(sdci[12]%10000)/10000;
1401 103190 fixed ra2=itofix(sdci[12]/10000);
1402 103190 fixed ra=ra1+ra2;
1403 103190 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1404 103190 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1405 103190 x1=xy[0];
1406 103190 y1=xy[1];
1407 103190 }
1408
1409
2/2
✓ Branch 0 taken 218 times.
✓ Branch 1 taken 102972 times.
103190 if(canscale) //scale first
1410 {
1411
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 218 times.
218 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1412 218 clear_bitmap(tempbit);
1413
1414 218 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1415
1416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if(opacity < 128)
1417 {
1418 clear_bitmap(prim_bmp);
1419 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1420 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1421 }
1422 else
1423 {
1424 218 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1425 }
1426
1427 218 destroy_bitmap(tempbit);
1428 218 }
1429 else //no scale
1430 {
1431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 102972 times.
102972 if(opacity < 128)
1432 {
1433 clear_bitmap(prim_bmp);
1434 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1435 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1436 }
1437 else
1438 {
1439 102972 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1440 }
1441 }
1442 103190 }
1443 else //scale only
1444 {
1445
1/2
✓ Branch 0 taken 23204 times.
✗ Branch 1 not taken.
23204 if(canscale)
1446 {
1447
2/2
✓ Branch 0 taken 9395 times.
✓ Branch 1 taken 13809 times.
23204 if(opacity<128)
1448 {
1449 9395 clear_bitmap(prim_bmp);
1450 9395 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1451 9395 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1452 9395 }
1453 else
1454 {
1455 13809 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1456 }
1457 23204 }
1458 else //error -do not scale
1459 {
1460 if(opacity<128)
1461 {
1462 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1463 }
1464 else
1465 {
1466 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1467 }
1468 }
1469 }
1470
1471 126394 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
1472 126394 }
1473 else // no scale or rotation
1474 {
1475
1/2
✓ Branch 0 taken 2618641 times.
✗ Branch 1 not taken.
2618641 if(transparency)
1476 {
1477
2/2
✓ Branch 0 taken 63540 times.
✓ Branch 1 taken 2555101 times.
2618641 if(opacity<=127)
1478 63540 TileHelper::OverTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1479 else
1480 2555101 TileHelper::OverTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1481 2618641 }
1482 else
1483 {
1484 if(opacity<=127)
1485 TileHelper::PutTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1486 else
1487 TileHelper::OldPutTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1488 }
1489 }
1490 2745108 }
1491
1492 void do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1493 {
1494 //sdci[1]=layer
1495 //sdci[2]=x
1496 //sdci[3]=y
1497 //sdci[4]=combo
1498 //sdci[5]=tile width
1499 //sdci[6]=tile height
1500 //sdci[7]=flip
1501
1502 int32_t w = sdci[5]/10000;
1503 int32_t h = sdci[6]/10000;
1504
1505 if(w<1||h<1||h>20||w>20)
1506 {
1507 return;
1508 }
1509 int32_t cmb = (sdci[4]/10000);
1510 if((unsigned)cmb >= MAXCOMBOS)
1511 {
1512 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1513 return;
1514 }
1515
1516 int32_t x1=sdci[2]/10000;
1517 int32_t y1=sdci[3]/10000;
1518
1519 auto& c = GET_DRAWING_COMBO(cmb);
1520 int32_t tiletodraw = combo_tile(c, x1, y1);
1521 if(c.animflags & AF_EDITOR_ONLY) return;
1522 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
1523 int32_t skiprows=c.skipanimy;
1524
1525 TileHelper::OverTileCloaked(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
1526 }
1527
1528
1529 5303765 void do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1530 {
1531 /* layer, x, y, tile, color opacity */
1532
1533 5303765 int32_t opacity = sdci[6]/10000;
1534 5303765 int x = xoffset+(sdci[2]/10000);
1535 5303765 int y = yoffset+(sdci[3]/10000);
1536
1537
2/2
✓ Branch 0 taken 154230 times.
✓ Branch 1 taken 5149535 times.
5303765 if(opacity < 128)
1538 154230 overtiletranslucent16(bmp, sdci[4]/10000, x, y, sdci[5]/10000, 0, opacity);
1539 else
1540 5149535 overtile16(bmp, sdci[4]/10000, x, y, sdci[5]/10000, 0);
1541 5303765 }
1542
1543 void do_fasttilesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1544 {
1545 /* layer, x, y, tile, color opacity */
1546
1547 //sdci[1]=layer
1548 //sdci[2]=array {x,y,tile,colour,opacity}
1549
1550 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1551
1552 if(!v_ptr)
1553 {
1554 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1555 return;
1556 }
1557
1558 std::vector<int32_t> &v = *v_ptr;
1559
1560 if(v.empty())
1561 return;
1562
1563 int32_t* pos = &v[0];
1564 int32_t sz = v.size();
1565
1566 for ( int32_t q = 0; q < sz; q+=5 )
1567 {
1568
1569 if(v.at(q+4) < 128)
1570 overtiletranslucent16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0, v.at(q+4));
1571 else
1572 overtile16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0);
1573 }
1574 }
1575
1576
1577
1578 22453186 void do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1579 {
1580 /* layer, x, y, tile, color opacity */
1581
1582 22453186 int32_t opacity = sdci[6] / 10000;
1583 22453186 int32_t x1 = sdci[2] / 10000;
1584 22453186 int32_t y1 = sdci[3] / 10000;
1585
1586 22453186 int32_t cmb = (sdci[4]/10000);
1587
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22453186 times.
22453186 if((unsigned)cmb >= MAXCOMBOS)
1588 {
1589 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1590 return;
1591 }
1592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22453186 times.
22453186 if(combobuf[cmb].animflags & AF_EDITOR_ONLY) return;
1593
1594 22453186 int x = xoffset+x1;
1595 22453186 int y = yoffset+y1;
1596
1597
2/2
✓ Branch 0 taken 177396 times.
✓ Branch 1 taken 22275790 times.
22453186 if(opacity < 128)
1598 {
1599 177396 overcomboblocktranslucent(bmp, x, y, cmb, sdci[5]/10000, 1, 1, 128);
1600 177396 }
1601 else
1602 {
1603 22275790 overcomboblock(bmp, x, y, cmb, sdci[5]/10000, 1, 1);
1604 }
1605 22453186 }
1606
1607 void do_fastcombosr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1608 {
1609 /* layer, x, y, combo, cset, opacity */
1610 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1611
1612 if(!v_ptr)
1613 {
1614 al_trace("Screen->FastCombos: Vector pointer is null! Internal error. \n");
1615 return;
1616 }
1617
1618 std::vector<int32_t> &v = *v_ptr;
1619
1620 if(v.empty())
1621 return;
1622
1623 int32_t* pos = &v[0];
1624 int32_t sz = v.size();
1625
1626 for ( int32_t q = 0; q < sz; q+=5 )
1627 {
1628 auto cid = v.at(q+2);
1629 if((unsigned)(cid) >= MAXCOMBOS)
1630 {
1631 Z_scripterrlog("FastCombos() cannot draw combo '%d', as it is out of bounds.\n", v.at(q+2));
1632 continue;
1633 }
1634 if(combobuf[cid].animflags & AF_EDITOR_ONLY) continue;
1635 if(v.at(q+4) < 128)
1636 {
1637 overcomboblocktranslucent(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1, 128);
1638
1639 }
1640 else
1641 {
1642 overcomboblock(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1);
1643 }
1644 }
1645 }
1646
1647
1648
1649
1650 963845 void do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1651 {
1652 //broken 2.50.2 and earlier drawcharacter()
1653
2/2
✓ Branch 0 taken 18543 times.
✓ Branch 1 taken 945302 times.
963845 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1654 {
1655 //sdci[1]=layer
1656 //sdci[2]=x
1657 //sdci[3]=y
1658 //sdci[4]=font
1659 //sdci[5]=color
1660 //sdci[6]=bg color
1661 //sdci[7]=strech x (width)
1662 //sdci[8]=stretch y (height)
1663 //sdci[9]=char
1664 //sdci[10]=opacity
1665
1666 18543 int32_t x=sdci[2]/10000;
1667 18543 int32_t y=sdci[3]/10000;
1668 18543 int32_t font_index=sdci[4]/10000;
1669 18543 int32_t color=sdci[5]/10000;
1670 18543 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1671 18543 int32_t w=sdci[7]/10000;
1672 18543 int32_t h=sdci[8]/10000;
1673 18543 char glyph=char(sdci[9]/10000);
1674 18543 int32_t opacity=sdci[10]/10000;
1675
1676 //safe check
1677
1/2
✓ Branch 0 taken 18543 times.
✗ Branch 1 not taken.
18543 if(bg_color < -1) bg_color = -1;
1678
1679
1/2
✓ Branch 0 taken 18543 times.
✗ Branch 1 not taken.
18543 if(w>512) w=512; //w=vbound(w,0,512);
1680
1681
1/2
✓ Branch 0 taken 18543 times.
✗ Branch 1 not taken.
18543 if(h>512) h=512; //h=vbound(h,0,512);
1682
1683 //undone
1684
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18543 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18543 if(w>0&&h>0)//stretch the character
1685 {
1686 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1687
1688 if(opacity < 128)
1689 {
1690 if(w>128||h>128)
1691 {
1692 clear_bitmap(prim_bmp);
1693
1694 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1695 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1696 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1697 }
1698 else //this is faster
1699 {
1700 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1701
1702 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1703 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1704 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1705
1706 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1707 }
1708 }
1709 else // no opacity
1710 {
1711 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1712 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1713 }
1714
1715 }
1716 else //no stretch
1717 {
1718
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18543 times.
18543 if(opacity < 128)
1719 {
1720 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1721 clear_bitmap(pbmp);
1722
1723 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1724 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1725
1726 destroy_bitmap(pbmp);
1727 }
1728 else // no opacity
1729 {
1730 18543 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1731 }
1732 }
1733 18543 }
1734
1735 else //2.53.0 fixed version and later.
1736 {
1737
1738 //sdci[1]=layer
1739 //sdci[2]=x
1740 //sdci[3]=y
1741 //sdci[4]=font
1742 //sdci[5]=color
1743 //sdci[6]=bg color
1744 //sdci[7]=strech x (width)
1745 //sdci[8]=stretch y (height)
1746 //sdci[9]=char
1747 //sdci[10]=opacity
1748
1749 945302 int32_t x=sdci[2]/10000;
1750 945302 int32_t y=sdci[3]/10000;
1751 945302 int32_t font_index=sdci[4]/10000;
1752 945302 int32_t color=sdci[5]/10000;
1753 945302 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1754 945302 int32_t w=sdci[7]/10000;
1755 945302 int32_t h=sdci[8]/10000;
1756 945302 char glyph=char(sdci[9]/10000);
1757 945302 int32_t opacity=sdci[10]/10000;
1758
1759 //safe check
1760
1/2
✓ Branch 0 taken 945302 times.
✗ Branch 1 not taken.
945302 if(bg_color < -1) bg_color = -1;
1761
1762
1/2
✓ Branch 0 taken 945302 times.
✗ Branch 1 not taken.
945302 if(w>512) w=512; //w=vbound(w,0,512);
1763
1764
1/2
✓ Branch 0 taken 945302 times.
✗ Branch 1 not taken.
945302 if(h>512) h=512; //h=vbound(h,0,512);
1765
1766 //undone
1767
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 945302 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
945302 if(w>0&&h>0)//stretch the character
1768 {
1769 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1770
1771 if(opacity < 128)
1772 {
1773 if(w>128||h>128)
1774 {
1775 clear_bitmap(prim_bmp);
1776
1777 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1778 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1779 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1780 }
1781 else //this is faster
1782 {
1783 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1784
1785 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1786 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1787 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1788
1789 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1790 }
1791 }
1792 else // no opacity
1793 {
1794 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1795 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1796 }
1797
1798 }
1799 else //no stretch
1800 {
1801
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 945302 times.
945302 if(opacity < 128)
1802 {
1803 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1804 clear_bitmap(pbmp);
1805
1806 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1807 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1808
1809 destroy_bitmap(pbmp);
1810 }
1811 else // no opacity
1812 {
1813 945302 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1814 }
1815 }
1816
1817 }
1818
1819 963845 }
1820
1821
1822 165084 void do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1823 {
1824 //broken 2.50.2 and earlier drawinteger()
1825
2/2
✓ Branch 0 taken 72655 times.
✓ Branch 1 taken 92429 times.
165084 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1826 {
1827 //sdci[1]=layer
1828 //sdci[2]=x
1829 //sdci[3]=y
1830 //sdci[4]=font
1831 //sdci[5]=color
1832 //sdci[6]=bg color
1833 //sdci[7]=strech x (width)
1834 //sdci[8]=stretch y (height)
1835 //sdci[9]=integer
1836 //sdci[10]=num decimal places
1837 //sdci[11]=opacity
1838
1839 72655 int32_t x=sdci[2]/10000;
1840 72655 int32_t y=sdci[3]/10000;
1841 72655 int32_t font_index=sdci[4]/10000;
1842 72655 int32_t color=sdci[5]/10000;
1843 72655 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1844 72655 int32_t w=sdci[7]/10000;
1845 72655 int32_t h=sdci[8]/10000;
1846 72655 int32_t decplace=sdci[10]/10000;
1847 72655 int32_t opacity=sdci[11]/10000;
1848
1849 //safe check
1850
1/2
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
72655 if(bg_color < -1) bg_color = -1;
1851
1852
1/2
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
72655 if(w>512) w=512; //w=vbound(w,0,512);
1853
1854
1/2
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
72655 if(h>512) h=512; //h=vbound(h,0,512);
1855
1856 char numbuf[15];
1857
1858
1/6
✓ Branch 0 taken 72655 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
72655 switch(decplace)
1859 {
1860 default:
1861 case 0:
1862 72655 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1863 72655 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1864
1865 case 1:
1866 //sprintf(numbuf,"%.01f",number);
1867 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1868 break;
1869
1870 case 2:
1871 //sprintf(numbuf,"%.02f",number);
1872 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1873 break;
1874
1875 case 3:
1876 //sprintf(numbuf,"%.03f",number);
1877 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1878 break;
1879
1880 case 4:
1881 //sprintf(numbuf,"%.04f",number);
1882 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1883 break;
1884 }
1885
1886
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 72655 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
72655 if(w>0&&h>0)//stretch
1887 {
1888 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1889
1890 if(opacity < 128)
1891 {
1892 if(w>128||h>128)
1893 {
1894 clear_bitmap(prim_bmp);
1895
1896 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1897 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1898 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1899 }
1900 else
1901 {
1902 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1903 clear_bitmap(pbmp2);
1904
1905 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1906 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1907 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1908
1909 destroy_bitmap(pbmp2);
1910 }
1911 }
1912 else // no opacity
1913 {
1914 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1915 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1916 }
1917
1918 }
1919 else //no stretch
1920 {
1921
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72655 times.
72655 if(opacity < 128)
1922 {
1923 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1924 clear_bitmap(pbmp);
1925
1926 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1927 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1928
1929 destroy_bitmap(pbmp);
1930 }
1931 else // no opacity
1932 {
1933 72655 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1934 }
1935 }
1936
1937 72655 }
1938
1939 else //2.53.0 fixed version and later.
1940 {
1941 //sdci[1]=layer
1942 //sdci[2]=x
1943 //sdci[3]=y
1944 //sdci[4]=font
1945 //sdci[5]=color
1946 //sdci[6]=bg color
1947 //sdci[7]=strech x (width)
1948 //sdci[8]=stretch y (height)
1949 //sdci[9]=integer
1950 //sdci[10]=num decimal places
1951 //sdci[11]=opacity
1952
1953 92429 int32_t x=sdci[2]/10000;
1954 92429 int32_t y=sdci[3]/10000;
1955 92429 int32_t font_index=sdci[4]/10000;
1956 92429 int32_t color=sdci[5]/10000;
1957 92429 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1958 92429 int32_t w=sdci[7]/10000;
1959 92429 int32_t h=sdci[8]/10000;
1960 92429 int32_t decplace=sdci[10]/10000;
1961 92429 int32_t opacity=sdci[11]/10000;
1962
1963 //safe check
1964
1/2
✓ Branch 0 taken 92429 times.
✗ Branch 1 not taken.
92429 if(bg_color < -1) bg_color = -1;
1965
1966
1/2
✓ Branch 0 taken 92429 times.
✗ Branch 1 not taken.
92429 if(w>512) w=512; //w=vbound(w,0,512);
1967
1968
1/2
✓ Branch 0 taken 92429 times.
✗ Branch 1 not taken.
92429 if(h>512) h=512; //h=vbound(h,0,512);
1969
1970 char numbuf[15];
1971
1972
1/6
✓ Branch 0 taken 92429 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
92429 switch(decplace)
1973 {
1974 default:
1975 case 0:
1976 92429 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1977 92429 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1978
1979 case 1:
1980 //sprintf(numbuf,"%.01f",number);
1981 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1982 break;
1983
1984 case 2:
1985 //sprintf(numbuf,"%.02f",number);
1986 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1987 break;
1988
1989 case 3:
1990 //sprintf(numbuf,"%.03f",number);
1991 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1992 break;
1993
1994 case 4:
1995 //sprintf(numbuf,"%.04f",number);
1996 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1997 break;
1998 }
1999
2000 //FONT* font=get_zc_font(sdci[4]/10000);
2001
2002
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 92429 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
92429 if(w>0&&h>0)//stretch
2003 {
2004 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
2005 clear_bitmap(pbmp);
2006 //script_drawing_commands.GetSmallTextureBitmap(1,1);
2007
2008 if(opacity < 128)
2009 {
2010 if(w>128||h>128)
2011 {
2012 clear_bitmap(prim_bmp);
2013
2014 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2015 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
2016 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
2017 }
2018 else
2019 {
2020 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
2021 clear_bitmap(pbmp2);
2022
2023 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2024 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
2025 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
2026
2027 destroy_bitmap(pbmp2);
2028 }
2029 }
2030 else // no opacity
2031 {
2032 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
2033 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
2034 }
2035
2036 }
2037 else //no stretch
2038 {
2039
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 92429 times.
92429 if(opacity < 128)
2040 {
2041 FONT* font = get_zc_font(font_index);
2042 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
2043 clear_bitmap(pbmp);
2044
2045 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
2046 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2047
2048 destroy_bitmap(pbmp);
2049 }
2050 else // no opacity
2051 {
2052 92429 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
2053 }
2054 }
2055 }
2056 165084 }
2057
2058
2059 1598985 void do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2060 {
2061 //sdci[1]=layer
2062 //sdci[2]=x
2063 //sdci[3]=y
2064 //sdci[4]=font
2065 //sdci[5]=color
2066 //sdci[6]=bg color
2067 //sdci[7]=format_option
2068 //sdci[8]=string
2069 //sdci[9]=opacity
2070
2071 1598985 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2072
2073
1/2
✓ Branch 0 taken 1598985 times.
✗ Branch 1 not taken.
1598985 if(!str)
2074 {
2075 al_trace("String pointer is null! Internal error. \n");
2076 return;
2077 }
2078
2079 1598985 int32_t x=sdci[2]/10000;
2080 1598985 int32_t y=sdci[3]/10000;
2081 1598985 FONT* font=get_zc_font(sdci[4]/10000);
2082 1598985 int32_t color=sdci[5]/10000;
2083 1598985 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2084 1598985 int32_t format_type=sdci[7]/10000;
2085 1598985 int32_t opacity=sdci[9]/10000;
2086 //sdci[8] not needed :)
2087
2088 //safe check
2089
1/2
✓ Branch 0 taken 1598985 times.
✗ Branch 1 not taken.
1598985 if(bg_color < -1) bg_color = -1;
2090
2091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1598985 times.
1598985 if(opacity < 128)
2092 {
2093 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2094 if (width < 1) return; //SANITY -Em
2095 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2096 clear_bitmap(pbmp);
2097 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2098 if(format_type == 2) // right-sided text
2099 x-=width;
2100 else if(format_type == 1) // centered text
2101 x-=width/2;
2102 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2103 destroy_bitmap(pbmp);
2104 }
2105 else // no opacity
2106 {
2107
2/2
✓ Branch 0 taken 14345 times.
✓ Branch 1 taken 1584640 times.
1598985 if(format_type == 2) // right-sided text
2108 {
2109 14345 textout_right_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2110 14345 }
2111
2/2
✓ Branch 0 taken 725712 times.
✓ Branch 1 taken 858928 times.
1584640 else if(format_type == 1) // centered text
2112 {
2113 725712 textout_centre_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2114 725712 }
2115 else // standard left-sided text
2116 {
2117 858928 textout_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2118 }
2119 }
2120 1598985 }
2121
2122 163716 void do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2123 {
2124 //sdci[1]=layer
2125 //sdci[2]=x
2126 //sdci[3]=y
2127 //sdci[4]=font
2128 //sdci[5]=color
2129 //sdci[6]=bg color
2130 //sdci[7]=format_option
2131 //sdci[8]=string
2132 //sdci[9]=opacity
2133 //sdci[10]=shadowtype
2134 //sdci[11]=shadow_color
2135
2136 163716 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2137
2138
1/2
✓ Branch 0 taken 163716 times.
✗ Branch 1 not taken.
163716 if(!str)
2139 {
2140 al_trace("String pointer is null! Internal error. \n");
2141 return;
2142 }
2143
2144 163716 int32_t x=sdci[2]/10000;
2145 163716 int32_t y=sdci[3]/10000;
2146 163716 FONT* font=get_zc_font(sdci[4]/10000);
2147 163716 int32_t color=sdci[5]/10000;
2148 163716 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2149 163716 int32_t format_type=sdci[7]/10000;
2150 163716 int32_t opacity=sdci[9]/10000;
2151 163716 int32_t textstyle = sdci[10]/10000;
2152 163716 int32_t shadow_color = sdci[11]/10000;
2153 //sdci[8] not needed :)
2154
2155 //safe check
2156
1/2
✓ Branch 0 taken 163716 times.
✗ Branch 1 not taken.
163716 if(bg_color < -1) bg_color = -1;
2157
2158
2/2
✓ Branch 0 taken 740 times.
✓ Branch 1 taken 162976 times.
163716 if(opacity < 128)
2159 {
2160
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2161
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 if (width < 1) return; //SANITY -Em
2162 740 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2163 740 clear_bitmap(pbmp);
2164 740 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
2165 740 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
740 if(format_type == 2) // right-sided text
2167 x-=width;
2168
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 else if(format_type == 1) // centered text
2169 740 x-=width/2;
2170 740 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2171 740 destroy_bitmap(pbmp);
2172 740 }
2173 else // no opacity
2174 {
2175 162976 textout_styled_aligned_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
2176 }
2177 163716 }
2178
2179
2180 9266 void do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2181 {
2182 //sdci[1]=layer
2183 //sdci[2]=x1
2184 //sdci[3]=y1
2185 //sdci[4]=x2
2186 //sdci[5]=y2
2187 //sdci[6]=x3
2188 //sdci[7]=y3
2189 //sdci[8]=x4
2190 //sdci[9]=y4
2191 //sdci[10]=width
2192 //sdci[11]=height
2193 //sdci[12]=cset
2194 //sdci[13]=flip
2195 //sdci[14]=tile/combo
2196 //sdci[15]=polytype
2197
2198 9266 int32_t x1 = sdci[2]/10000;
2199 9266 int32_t y1 = sdci[3]/10000;
2200 9266 int32_t x2 = sdci[4]/10000;
2201 9266 int32_t y2 = sdci[5]/10000;
2202 9266 int32_t x3 = sdci[6]/10000;
2203 9266 int32_t y3 = sdci[7]/10000;
2204 9266 int32_t x4 = sdci[8]/10000;
2205 9266 int32_t y4 = sdci[9]/10000;
2206 9266 int32_t w = sdci[10]/10000;
2207 9266 int32_t h = sdci[11]/10000;
2208 9266 int32_t color = sdci[12]/10000;
2209 9266 int32_t flip=(sdci[13]/10000)&3;
2210 9266 int32_t tile = sdci[14]/10000;
2211 9266 int32_t polytype = sdci[15]/10000;
2212
2213 //todo: finish palette shading
2214 /*
2215 POLYTYPE_FLAT
2216 POLYTYPE_GCOL
2217 POLYTYPE_GRGB
2218 POLYTYPE_ATEX
2219 POLYTYPE_PTEX
2220 POLYTYPE_ATEX_MASK
2221 POLYTYPE_PTEX_MASK
2222 POLYTYPE_ATEX_LIT
2223 POLYTYPE_PTEX_LIT
2224 POLYTYPE_ATEX_MASK_LIT
2225 POLYTYPE_PTEX_MASK_LIT
2226 POLYTYPE_ATEX_TRANS
2227 POLYTYPE_PTEX_TRANS
2228 POLYTYPE_ATEX_MASK_TRANS
2229 POLYTYPE_PTEX_MASK_TRANS
2230 */
2231 9266 polytype = vbound(polytype, 0, 14);
2232
2233
2/4
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9266 times.
9266 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2234 {
2235 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2236 return; //non power of two error
2237 }
2238
2239 9266 int32_t tex_width = w*16;
2240 9266 int32_t tex_height = h*16;
2241
2242 BITMAP *tex;
2243
2244 9266 bool mustDestroyBmp = false;
2245
2246
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile > 65519 ) tex = zscriptDrawingRenderTarget->GetBitmapPtr(tile - 65519);
2247 9266 else tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2248
2249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if(!tex)
2250 {
2251 mustDestroyBmp = true;
2252 tex = create_bitmap_ex(8, tex_width, tex_height);
2253 clear_bitmap(tex);
2254 }
2255
2256 int32_t col[4];
2257 /*
2258 if( color < 0 )
2259 {
2260 col[0]=draw_container.color_buffer[0];
2261 col[1]=draw_container.color_buffer[1];
2262 col[2]=draw_container.color_buffer[2];
2263 col[3]=draw_container.color_buffer[3];
2264 }
2265 else */
2266 {
2267 9266 col[0]=col[1]=col[2]=col[3]=color;
2268 }
2269
2270
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9266 if(tile > 0 && tile <= 65519) // TILE
2271 {
2272 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2273 }
2274
2275
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if ( tile < 0 ) // COMBO
2276 {
2277 9266 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
2278 9266 const int32_t tiletodraw = combo_tile(c, x1, y1);
2279 9266 flip = flip ^ c.flip;
2280
2281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if(!(c.animflags & AF_EDITOR_ONLY))
2282 9266 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2283 9266 }
2284
2285 9266 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2286 9266 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2287 9266 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2288 9266 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(tex_width), 0, col[3] };
2289
2290 9266 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
2291
2292
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(mustDestroyBmp)
2293 destroy_bitmap(tex);
2294
2295 9266 }
2296
2297
2298 void do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2299 {
2300 //sdci[1]=layer
2301 //sdci[2]=x1
2302 //sdci[3]=y1
2303 //sdci[4]=x2
2304 //sdci[5]=y2
2305 //sdci[6]=x3
2306 //sdci[7]=y3
2307 //sdci[8]=width
2308 //sdci[9]=height
2309 //sdci[10]=cset
2310 //sdci[11]=flip
2311 //sdci[12]=tile/combo
2312 //sdci[13]=polytype
2313
2314 int32_t x1 = sdci[2]/10000;
2315 int32_t y1 = sdci[3]/10000;
2316 int32_t x2 = sdci[4]/10000;
2317 int32_t y2 = sdci[5]/10000;
2318 int32_t x3 = sdci[6]/10000;
2319 int32_t y3 = sdci[7]/10000;
2320 int32_t w = sdci[8]/10000;
2321 int32_t h = sdci[9]/10000;
2322 int32_t color = sdci[10]/10000;
2323 int32_t flip=(sdci[11]/10000)&3;
2324 int32_t tile = sdci[12]/10000;
2325 int32_t polytype = sdci[13]/10000;
2326
2327 polytype = vbound(polytype, 0, 14);
2328
2329 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2330 {
2331 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2332 return; //non power of two error
2333 }
2334
2335 int32_t tex_width = w*16;
2336 int32_t tex_height = h*16;
2337
2338 bool mustDestroyBmp = false;
2339 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2340
2341 if(!tex)
2342 {
2343 mustDestroyBmp = true;
2344 tex = create_bitmap_ex(8, tex_width, tex_height);
2345 clear_bitmap(tex);
2346 }
2347
2348 int32_t col[3];
2349 /*
2350 if( color < 0 )
2351 {
2352 col[0]=draw_container.color_buffer[0];
2353 col[1]=draw_container.color_buffer[1];
2354 col[2]=draw_container.color_buffer[2];
2355 }
2356 else */
2357 {
2358 col[0]=col[1]=col[2]=color;
2359 }
2360
2361 if(tile > 0) // TILE
2362 {
2363 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2364 }
2365 else // COMBO
2366 {
2367 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
2368 const int32_t tiletodraw = combo_tile(c, x1, y1);
2369 flip = flip ^ c.flip;
2370
2371 if(!(c.animflags & AF_EDITOR_ONLY))
2372 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2373 }
2374
2375 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2376 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2377 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2378
2379
2380 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
2381
2382 if(mustDestroyBmp)
2383 destroy_bitmap(tex);
2384 }
2385
2386
2387 933060 void do_drawbitmapr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2388 {
2389 //sdci[1]=layer
2390 //sdci[2]=bitmap
2391 //sdci[3]=sourcex
2392 //sdci[4]=sourcey
2393 //sdci[5]=sourcew
2394 //sdci[6]=sourceh
2395 //sdci[7]=destx
2396 //sdci[8]=desty
2397 //sdci[9]=destw
2398 //sdci[10]=desth
2399 //sdci[11]=rotation
2400 //sdci[12]=mask
2401
2402 933060 int32_t bitmapIndex = sdci[2]/10000;
2403 933060 int32_t sx = sdci[3]/10000;
2404 933060 int32_t sy = sdci[4]/10000;
2405 933060 int32_t sw = sdci[5]/10000;
2406 933060 int32_t sh = sdci[6]/10000;
2407 933060 int32_t dx = sdci[7]/10000;
2408 933060 int32_t dy = sdci[8]/10000;
2409 933060 int32_t dw = sdci[9]/10000;
2410 933060 int32_t dh = sdci[10]/10000;
2411 933060 float rot = sdci[11]/10000;
2412 933060 bool masked = (sdci[12] != 0);
2413
2414 //bugfix
2415 933060 sx = vbound(sx, 0, 512);
2416 933060 sy = vbound(sy, 0, 512);
2417 933060 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2418 933060 sh = vbound(sh, 0, 512 - sy);
2419
2420
2421
2/4
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 933060 times.
933060 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2422 return;
2423
2424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 933060 times.
933060 bool stretched = (sw != dw || sh != dh);
2425
2426 933060 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2427
2428
1/2
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
933060 if(!sourceBitmap)
2429 {
2430 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2431 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2432 return;
2433 }
2434
2435 933060 BITMAP* subBmp = 0;
2436
2437
1/2
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
933060 if(rot != 0)
2438 {
2439 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2440
2441 if(!subBmp)
2442 {
2443 Z_scripterrlog("DrawBitmap() failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2444 return;
2445 }
2446 }
2447
2448
2449 933060 dx = dx + xoffset;
2450 933060 dy = dy + yoffset;
2451
2452
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 932820 times.
933060 if(stretched)
2453 {
2454
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(masked)
2455 {
2456
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(rot != 0)
2457 {
2458 //if ( rot == 4096 ) { //translucent
2459 // masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2460 // //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2461 // draw_trans_sprite(bmp, subBmp, dx, dy);
2462 // //draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, 0);
2463
2464
2465 // }
2466 //else {
2467 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2468 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2469 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2470 //
2471
2472 // }
2473 }
2474 else
2475 240 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2476 240 }
2477 else
2478 {
2479 if(rot != 0)
2480 {
2481 //if ( rot == 4096 ) { //translucent
2482 // stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2483 // draw_trans_sprite(bmp, subBmp, dx, dy);
2484 // }
2485 //else {
2486 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2487 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2488 // }
2489 }
2490 else
2491 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2492 }
2493 240 }
2494 else
2495 {
2496
2/2
✓ Branch 0 taken 928098 times.
✓ Branch 1 taken 4722 times.
932820 if(masked)
2497 {
2498
1/2
✓ Branch 0 taken 928098 times.
✗ Branch 1 not taken.
928098 if(rot != 0)
2499 {
2500 //if ( rot == 4096 ) {//translucent
2501 // masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2502 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2503
2504 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2505 //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2506 // draw_trans_sprite(bmp, subBmp, dx, dy);
2507 // }
2508 //else {
2509 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2510 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2511 // }
2512 }
2513 else
2514 928098 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2515 928098 }
2516 else
2517 {
2518
1/2
✓ Branch 0 taken 4722 times.
✗ Branch 1 not taken.
4722 if(rot != 0)
2519 {
2520 //if ( rot == 4096 ) { //translucent
2521 // blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2522 // draw_trans_sprite(bmp, subBmp, dx, dy);
2523 // }
2524 //else {
2525 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2526 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2527 // }
2528 }
2529 else
2530 4722 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2531 }
2532 }
2533
2534 //cleanup
2535
1/2
✓ Branch 0 taken 933060 times.
✗ Branch 1 not taken.
933060 if(subBmp)
2536 {
2537 script_drawing_commands.ReleaseSubBitmap(subBmp);
2538 }
2539 933060 }
2540
2541
2542 //Draw]()
2543 void do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2544 {
2545 /*
2546 //sdci[1]=layer
2547 //sdci[2]=bitmap
2548 //sdci[3]=sourcex
2549 //sdci[4]=sourcey
2550 //sdci[5]=sourcew
2551 //sdci[6]=sourceh
2552 //sdci[7]=destx
2553 //sdci[8]=desty
2554 //sdci[9]=destw
2555 //sdci[10]=desth
2556 //sdci[11]=rotation/angle
2557 //scdi[12] = pivot cx
2558 //sdci[13] = pivot cy
2559 //scdi[14] = effect flags
2560
2561
2562 const int32_t BITDX_NORMAL = 0;
2563 const int32_t BITDX_TRANS = 1; //Translucent
2564 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
2565 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
2566 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
2567 //Note: Some modes cannot be combined. if a combination is not supported, an error
2568 // detailing this will be shown in allegro.log.
2569
2570 //scdi[15] = litcolour
2571 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2572 /not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2573
2574 //sdci[16]=mask
2575
2576 */
2577
2578 int32_t bitmapIndex = sdci[2]/10000;
2579 int32_t sx = sdci[3]/10000;
2580 int32_t sy = sdci[4]/10000;
2581 int32_t sw = sdci[5]/10000;
2582 int32_t sh = sdci[6]/10000;
2583 int32_t dx = sdci[7]/10000;
2584 int32_t dy = sdci[8]/10000;
2585 int32_t dw = sdci[9]/10000;
2586 int32_t dh = sdci[10]/10000;
2587 float rot = sdci[11]/10000;
2588 int32_t cx = sdci[12]/10000;
2589 int32_t cy = sdci[13]/10000;
2590 int32_t mode = sdci[14]/10000;
2591 int32_t litcolour = sdci[15]/10000;
2592 bool masked = (sdci[16] != 0);
2593
2594
2595
2596 //bugfix
2597 sx = vbound(sx, 0, 512);
2598 sy = vbound(sy, 0, 512);
2599 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2600 sh = vbound(sh, 0, 512 - sy);
2601
2602
2603 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2604 return;
2605
2606 bool stretched = (sw != dw || sh != dh);
2607
2608 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2609
2610 if(!sourceBitmap)
2611 {
2612 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2613 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2614 return;
2615 }
2616
2617 BITMAP* subBmp = 0;
2618
2619 /*
2620 if ( bitmapIndex == -1 ) {
2621 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
2622 }
2623 */
2624
2625 if(rot != 0 || mode != 0)
2626 {
2627 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2628
2629 if(!subBmp)
2630 {
2631 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2632 return;
2633 }
2634 }
2635
2636
2637 dx = dx + xoffset;
2638 dy = dy + yoffset;
2639
2640 if(stretched)
2641 {
2642 if(masked) //stretched and masked
2643 {
2644 if ( rot == 0 ) //if not rotated
2645 {
2646 switch(mode)
2647 {
2648 case 1:
2649 //transparent
2650 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2651 draw_trans_sprite(bmp, subBmp, dx, dy);
2652 break;
2653
2654
2655 case 2:
2656 //pivot?
2657 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2658 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2659 //Pivoting requires two more args
2660 break;
2661
2662 case 3:
2663 //pivot + trans
2664 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2665 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2666 break;
2667
2668 case 4:
2669 //flip v
2670 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2671 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2672 break;
2673
2674 case 5:
2675 //trans + v flip
2676 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2677 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2678 break;
2679
2680 case 6:
2681 //pivot + v flip
2682 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2683 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2684 break;
2685
2686 case 8:
2687 //vlip h
2688 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2689 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2690 break;
2691
2692 case 9:
2693 //trans + h flip
2694 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2695 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2696 break;
2697
2698 case 10:
2699 //flip H and pivot
2700 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2701 //return error cannot pivot and h flip
2702 break;
2703
2704 case 12:
2705 //vh flip
2706 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2707 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2708 break;
2709
2710 case 13:
2711 //trans + vh flip
2712 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2713 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2714 break;
2715
2716 case 14:
2717 //pivot and vh flip
2718 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2719 //return error cannot both pivot and vh flip
2720 break;
2721
2722 case 16:
2723 //lit
2724 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2725 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2726 break;
2727
2728 case 18:
2729 //pivot, lit
2730 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2731 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2732 break;
2733
2734 case 20:
2735 //lit + v flip
2736 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2737 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2738 break;
2739
2740 case 22:
2741 //Pivot, vflip, lit
2742 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2743 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2744 break;
2745
2746 case 24:
2747 //lit + h flip
2748 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2749 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2750 break;
2751
2752 case 26:
2753 //pivot + lit + hflip
2754 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2755 //return error cannot pivot, lit, and flip
2756 break;
2757
2758 case 28:
2759 //lit + vh flip
2760 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2761 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2762 break;
2763
2764 case 32: //gouraud
2765 //Probably not wort supporting.
2766 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2767 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2768 break;
2769
2770 case 0:
2771 //no effect
2772 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2773 break;
2774
2775
2776 default:
2777 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2778
2779
2780 }
2781 } //end if not rotated
2782
2783 if ( rot != 0 ) //if rotated
2784 {
2785 switch(mode)
2786 {
2787 case 1:
2788 //transparent
2789 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2790 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2791
2792 break;
2793
2794 case 2:
2795 //pivot?
2796 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2797 //return an error, cannot both rotate and pivot
2798 break;
2799
2800 case 3:
2801 //pivot + trans
2802 //return an error, cannot both rotate and pivot
2803 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2804 break;
2805
2806 case 4:
2807 //flip v
2808 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2809 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2810 break;
2811
2812 case 5:
2813 //trans + v flip
2814 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2815 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2816 break;
2817
2818 case 6:
2819 //pivot + v flip
2820 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2821 //return an error, cannot both rotate and pivot
2822 break;
2823
2824 case 8:
2825 //flip h
2826 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
2827 //return an error, cannot both rotate and flip H
2828 break;
2829
2830 case 9:
2831 //trans + h flip
2832 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
2833 //return an error, cannot rotate and flip a trans sprite
2834 break;
2835
2836 case 10:
2837 //flip H and pivot
2838 //return error cannot pivot and h flip
2839 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2840 break;
2841
2842 case 12:
2843 //vh flip
2844 //return an error, cannot rotate and VH flip a trans sprite
2845 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2846 break;
2847
2848 case 13:
2849 //trans + vh flip
2850 //return an error, cannot rotate and VH flip a trans sprite
2851 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2852 break;
2853
2854 case 14:
2855 //pivot and vh flip
2856 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2857 //return error cannot both pivot and vh flip
2858 break;
2859
2860 case 16:
2861 //lit
2862 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2863 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2864 break;
2865
2866 case 18:
2867 //pivot, lit
2868 //return an error, cannot both rotate and pivot
2869 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2870 break;
2871
2872 case 20:
2873 //lit + vflip
2874 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2875 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2876 break;
2877
2878 case 22:
2879 //Pivot, vflip, lit
2880 //return an error, cannot both rotate and pivot
2881 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2882 break;
2883
2884 case 24:
2885 //lit + h flip
2886 //return an error, cannot both rotate and H flip
2887 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
2888 break;
2889
2890 case 26:
2891 //pivot + lit + hflip
2892 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
2893 //return error cannot pivot, lit, and flip
2894 break;
2895
2896 case 28:
2897 //lit + vh flip
2898 //return an error, cannot both rotate and VH flip
2899 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2900 break;
2901
2902 case 32: //gouraud
2903 //Probably not wort supporting.
2904 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2905 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2906 break;
2907
2908 case 0:
2909 //no effect.
2910 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2911 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2912 break;
2913
2914 default:
2915 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2916
2917 }
2918 }
2919 } //end if stretched and masked
2920
2921 else //stretched, not masked
2922 {
2923 if ( rot == 0 ) //if not rotated
2924 {
2925 switch(mode) {
2926 case 1:
2927 //transparent
2928 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2929 draw_trans_sprite(bmp, subBmp, dx, dy);
2930 break;
2931
2932
2933 case 2:
2934 //pivot?
2935 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2936 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2937 //Pivoting requires two more args
2938 break;
2939
2940 case 3:
2941 //pivot + trans
2942 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2943 pivot_sprite_trans(bmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
2944 break;
2945
2946 case 4:
2947 //flip v
2948 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2949 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2950 break;
2951
2952 case 5:
2953 //trans + v flip
2954 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2955 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2956 break;
2957
2958 case 6:
2959 //pivot + v flip
2960 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2961 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2962 break;
2963
2964 case 8:
2965 //vlip h
2966 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2967 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2968 break;
2969
2970 case 9:
2971 //trans + h flip
2972 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2973 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2974 break;
2975
2976 case 10:
2977 //flip H and pivot
2978 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2979 //return error cannot pivot and h flip
2980 break;
2981
2982 case 12:
2983 //vh flip
2984 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2985 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2986 break;
2987
2988 case 13:
2989 //trans + vh flip
2990 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2991 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2992 break;
2993
2994 case 14:
2995 //pivot and vh flip
2996 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2997 //return error cannot both pivot and vh flip
2998 break;
2999
3000 case 16:
3001 //lit
3002 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3003 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3004 break;
3005
3006 case 18:
3007 //pivot, lit
3008 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3009 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3010 break;
3011
3012 case 20:
3013 //lit + v flip
3014 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3015 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3016 break;
3017
3018 case 22:
3019 //Pivot, vflip, lit
3020 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3021 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3022 break;
3023
3024 case 24:
3025 //lit + h flip
3026 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3027 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3028 break;
3029
3030 case 26:
3031 //pivot + lit + hflip
3032 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3033 //return error cannot pivot, lit, and flip
3034 break;
3035
3036 case 28:
3037 //lit + vh flip
3038 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3039 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3040 break;
3041
3042 case 32: //gouraud
3043 //Probably not wort supporting.
3044 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3045 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3046 break;
3047
3048 case 0:
3049 //no effect
3050 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
3051 break;
3052
3053
3054 default:
3055 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3056
3057
3058 }
3059 } //end if not rotated
3060
3061 if ( rot != 0 ) //if rotated
3062 {
3063 switch(mode)
3064 {
3065 case 1:
3066 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3067 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3068
3069 break;
3070
3071 case 2:
3072 //pivot?
3073 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3074 //return an error, cannot both rotate and pivot
3075 break;
3076
3077 case 3:
3078 //pivot + trans
3079 //return an error, cannot both rotate and pivot
3080 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3081 break;
3082
3083 case 4:
3084 //flip v
3085 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3086 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3087 break;
3088
3089 case 5:
3090 //trans + v flip
3091 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3092 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3093 break;
3094
3095 case 6:
3096 //pivot + v flip
3097 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3098 //return an error, cannot both rotate and pivot
3099 break;
3100
3101 case 8:
3102 //flip h
3103 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3104 //return an error, cannot both rotate and flip H
3105 break;
3106
3107 case 9:
3108 //trans + h flip
3109 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3110 //return an error, cannot rotate and flip a trans sprite
3111 break;
3112
3113 case 10:
3114 //flip H and pivot
3115 //return error cannot pivot and h flip
3116 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3117 break;
3118
3119 case 12:
3120 //vh flip
3121 //return an error, cannot rotate and VH flip a trans sprite
3122 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3123 break;
3124
3125 case 13:
3126 //trans + vh flip
3127 //return an error, cannot rotate and VH flip a trans sprite
3128 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3129 break;
3130
3131 case 14:
3132 //pivot and vh flip
3133 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3134 //return error cannot both pivot and vh flip
3135 break;
3136
3137 case 16:
3138 //lit
3139 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3140 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3141 break;
3142
3143 case 18:
3144 //pivot, lit
3145 //return an error, cannot both rotate and pivot
3146 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3147 break;
3148
3149 case 20:
3150 //lit + vflip
3151 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3152 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3153 break;
3154
3155 case 22:
3156 //Pivot, vflip, lit
3157 //return an error, cannot both rotate and pivot
3158 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3159 break;
3160
3161 case 24:
3162 //lit + h flip
3163 //return an error, cannot both rotate and H flip
3164 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3165 break;
3166
3167 case 26:
3168 //pivot + lit + hflip
3169 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3170 //return error cannot pivot, lit, and flip
3171 break;
3172
3173 case 28:
3174 //lit + vh flip
3175 //return an error, cannot both rotate and VH flip
3176 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3177 break;
3178
3179 case 32: //gouraud
3180 //Probably not wort supporting.
3181 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3182 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3183 break;
3184
3185 case 0:
3186 //no effect.
3187 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3188 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3189 break;
3190
3191 default:
3192 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3193
3194 }
3195 }
3196
3197 } //end if stretched, but not masked
3198 }
3199 else //not stretched
3200 {
3201
3202 if(masked) //if masked, but not stretched
3203 {
3204
3205 if ( rot == 0 ) //if not rotated
3206 {
3207 switch(mode)
3208 {
3209 case 1:
3210 //transparent
3211 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3212 draw_trans_sprite(bmp, subBmp, dx, dy);
3213 break;
3214
3215
3216 case 2:
3217 //pivot?
3218 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3219 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3220 //Pivoting requires two more args
3221 break;
3222
3223 case 3:
3224 //pivot + trans
3225 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3226 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3227 break;
3228
3229 case 4:
3230 //flip v
3231 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3232 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3233 break;
3234
3235 case 5:
3236 //trans + v flip
3237 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3238 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3239 break;
3240
3241 case 6:
3242 //pivot + v flip
3243 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3244 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3245 break;
3246
3247 case 8:
3248 //vlip h
3249 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3250 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3251 break;
3252
3253 case 9:
3254 //trans + h flip
3255 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3256 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3257 break;
3258
3259 case 10:
3260 //flip H and pivot
3261 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3262 //return error cannot pivot and h flip
3263 break;
3264
3265 case 12:
3266 //vh flip
3267 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3268 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3269 break;
3270
3271 case 13:
3272 //trans + vh flip
3273 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3274 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3275 break;
3276
3277 case 14:
3278 //pivot and vh flip
3279 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3280 //return error cannot both pivot and vh flip
3281 break;
3282
3283 case 16:
3284 //lit
3285 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3286 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3287 break;
3288
3289 case 18:
3290 //pivot, lit
3291 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3292 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3293 break;
3294
3295 case 20:
3296 //lit + v flip
3297 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3298 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3299 break;
3300
3301 case 22:
3302 //Pivot, vflip, lit
3303 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3304 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3305 break;
3306
3307 case 24:
3308 //lit + h flip
3309 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3310 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3311 break;
3312
3313 case 26:
3314 //pivot + lit + hflip
3315 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3316 //return error cannot pivot, lit, and flip
3317 break;
3318
3319 case 28:
3320 //lit + vh flip
3321 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3322 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3323 break;
3324
3325 case 32: //gouraud
3326 //Probably not wort supporting.
3327 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3328 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3329 break;
3330
3331 case 0:
3332 //no effect
3333 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3334 break;
3335
3336
3337 default:
3338 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3339
3340
3341 }
3342 } //end if not rotated
3343
3344 if ( rot != 0 ) //if rotated
3345 {
3346 switch(mode)
3347 {
3348 case 1:
3349 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //transparent
3350 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3351
3352 break;
3353
3354 case 2:
3355 //pivot?
3356 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3357 //return an error, cannot both rotate and pivot
3358 break;
3359
3360 case 3:
3361 //pivot + trans
3362 //return an error, cannot both rotate and pivot
3363 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3364 break;
3365
3366 case 4:
3367 //flip v
3368 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3369 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3370 break;
3371
3372 case 5:
3373 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
3374 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3375 break;
3376
3377 case 6:
3378 //pivot + v flip
3379 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3380 //return an error, cannot both rotate and pivot
3381 break;
3382
3383 case 8:
3384 //flip h
3385 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3386 //return an error, cannot both rotate and flip H
3387 break;
3388
3389 case 9:
3390 //trans + h flip
3391 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3392 //return an error, cannot rotate and flip a trans sprite
3393 break;
3394
3395 case 10:
3396 //flip H and pivot
3397 //return error cannot pivot and h flip
3398 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3399 break;
3400
3401 case 12:
3402 //vh flip
3403 //return an error, cannot rotate and VH flip a trans sprite
3404 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3405 break;
3406
3407 case 13:
3408 //trans + vh flip
3409 //return an error, cannot rotate and VH flip a trans sprite
3410 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3411 break;
3412
3413 case 14:
3414 //pivot and vh flip
3415 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3416 //return error cannot both pivot and vh flip
3417 break;
3418
3419 case 16:
3420 //lit
3421 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3422 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3423 break;
3424
3425 case 18:
3426 //pivot, lit
3427 //return an error, cannot both rotate and pivot
3428 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3429 break;
3430
3431 case 20:
3432 //lit + vflip
3433 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3434 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3435 break;
3436
3437 case 22:
3438 //Pivot, vflip, lit
3439 //return an error, cannot both rotate and pivot
3440 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3441 break;
3442
3443 case 24:
3444 //lit + h flip
3445 //return an error, cannot both rotate and H flip
3446 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3447 break;
3448
3449 case 26:
3450 //pivot + lit + hflip
3451 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3452 //return error cannot pivot, lit, and flip
3453 break;
3454
3455 case 28:
3456 //lit + vh flip
3457 //return an error, cannot both rotate and VH flip
3458 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3459 break;
3460
3461 case 32: //gouraud
3462 //Probably not wort supporting.
3463 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3464 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3465 break;
3466
3467 case 0:
3468 //no effect.
3469 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3470 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3471 break;
3472
3473 default:
3474 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3475
3476 }
3477 } //end rtated, masked
3478 } //end if masked
3479
3480 else //not masked, and not stretched; just blit
3481 {
3482
3483 if ( rot == 0 ) //if not rotated
3484 {
3485 switch(mode)
3486 {
3487 case 1:
3488 //transparent
3489 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3490 draw_trans_sprite(bmp, subBmp, dx, dy);
3491 break;
3492
3493
3494 case 2:
3495 //pivot?
3496 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3497 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3498 //Pivoting requires two more args
3499 break;
3500
3501 case 3:
3502 //pivot + trans
3503 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3504 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3505 break;
3506
3507 case 4:
3508 //flip v
3509 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3510 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3511 break;
3512
3513 case 5:
3514 //trans + v flip
3515 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3516 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3517 break;
3518
3519 case 6:
3520 //pivot + v flip
3521 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3522 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3523 break;
3524
3525 case 8:
3526 //vlip h
3527 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3528 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3529 break;
3530
3531 case 9:
3532 //trans + h flip
3533 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3534 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3535 break;
3536
3537 case 10:
3538 //flip H and pivot
3539 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3540 //return error cannot pivot and h flip
3541 break;
3542
3543 case 12:
3544 //vh flip
3545 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3546 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3547 break;
3548
3549 case 13:
3550 //trans + vh flip
3551 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3552 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3553 break;
3554
3555 case 14:
3556 //pivot and vh flip
3557 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3558 //return error cannot both pivot and vh flip
3559 break;
3560
3561 case 16:
3562 //lit
3563 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3564 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3565 break;
3566
3567 case 18:
3568 //pivot, lit
3569 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3570 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3571 break;
3572
3573 case 20:
3574 //lit + v flip
3575 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3576 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3577 break;
3578
3579 case 22:
3580 //Pivot, vflip, lit
3581 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3582 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3583 break;
3584
3585 case 24:
3586 //lit + h flip
3587 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3588 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3589 break;
3590
3591 case 26:
3592 //pivot + lit + hflip
3593 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3594 //return error cannot pivot, lit, and flip
3595 break;
3596
3597 case 28:
3598 //lit + vh flip
3599 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3600 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3601 break;
3602
3603 case 32: //gouraud
3604 //Probably not wort supporting.
3605 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3606 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3607 break;
3608
3609 case 0:
3610 //no effect
3611 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3612 break;
3613
3614
3615 default:
3616 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3617
3618
3619 }
3620 } //end if not rotated
3621
3622 if ( rot != 0 ) //if rotated
3623 {
3624 switch(mode)
3625 {
3626 case 1:
3627 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);//transparent
3628 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3629
3630 break;
3631
3632 case 2:
3633 //pivot?
3634 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3635 //return an error, cannot both rotate and pivot
3636 break;
3637
3638 case 3:
3639 //pivot + trans
3640 //return an error, cannot both rotate and pivot
3641 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3642 break;
3643
3644 case 4:
3645 //flip v
3646 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3647 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3648 break;
3649
3650 case 5:
3651 //trans + v flip
3652 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3653 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3654 break;
3655
3656 case 6:
3657 //pivot + v flip
3658 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3659 //return an error, cannot both rotate and pivot
3660 break;
3661
3662 case 8:
3663 //flip h
3664 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3665 //return an error, cannot both rotate and flip H
3666 break;
3667
3668 case 9:
3669 //trans + h flip
3670 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3671 //return an error, cannot rotate and flip a trans sprite
3672 break;
3673
3674 case 10:
3675 //flip H and pivot
3676 //return error cannot pivot and h flip
3677 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3678 break;
3679
3680 case 12:
3681 //vh flip
3682 //return an error, cannot rotate and VH flip a trans sprite
3683 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3684 break;
3685
3686 case 13:
3687 //trans + vh flip
3688 //return an error, cannot rotate and VH flip a trans sprite
3689 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3690 break;
3691
3692 case 14:
3693 //pivot and vh flip
3694 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3695 //return error cannot both pivot and vh flip
3696 break;
3697
3698 case 16:
3699 //lit
3700 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3701 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3702 break;
3703
3704 case 18:
3705 //pivot, lit
3706 //return an error, cannot both rotate and pivot
3707 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3708 break;
3709
3710 case 20:
3711 //lit + vflip
3712 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3713 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3714 break;
3715
3716 case 22:
3717 //Pivot, vflip, lit
3718 //return an error, cannot both rotate and pivot
3719 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3720 break;
3721
3722 case 24:
3723 //lit + h flip
3724 //return an error, cannot both rotate and H flip
3725 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3726 break;
3727
3728 case 26:
3729 //pivot + lit + hflip
3730 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3731 //return error cannot pivot, lit, and flip
3732 break;
3733
3734 case 28:
3735 //lit + vh flip
3736 //return an error, cannot both rotate and VH flip
3737 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3738 break;
3739
3740 case 32: //gouraud
3741 //Probably not wort supporting.
3742 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3743 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3744 break;
3745
3746 case 0:
3747 //no effect.
3748 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3749 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3750 break;
3751
3752 default:
3753 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3754
3755 }
3756 } //end if rotated
3757 } //end if not masked
3758 } //end if not stretched
3759
3760 //cleanup
3761 if(subBmp)
3762 {
3763 script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
3764 }
3765 }
3766
3767
3768 void do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3769 {
3770 //sdci[1]=layer
3771 //sdci[2]=pos[12]
3772 //sdci[3]=uv[8]
3773 //sdci[4]=color[4]
3774 //sdci[5]=size[2]
3775 //sdci[6]=flip
3776 //sdci[7]=tile/combo
3777 //sdci[8]=polytype
3778
3779 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3780
3781 if(!v_ptr)
3782 {
3783 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
3784 return;
3785 }
3786
3787 std::vector<int32_t> &v = *v_ptr;
3788
3789 if(v.empty())
3790 return;
3791
3792 int32_t* pos = &v[0];
3793 int32_t* uv = &v[12];
3794 int32_t* col = &v[20];
3795 int32_t* size = &v[24];
3796
3797 int32_t w = size[0]; //magic numerical constants... yuck.
3798 int32_t h = size[1];
3799 int32_t flip = (sdci[6]/10000)&3;
3800 int32_t tile = sdci[7]/10000;
3801 int32_t polytype = sdci[8]/10000;
3802
3803 polytype = vbound(polytype, 0, 14);
3804
3805 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3806 {
3807 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3808 return; //non power of two error
3809 }
3810
3811 int32_t tex_width = w*16;
3812 int32_t tex_height = h*16;
3813
3814 bool mustDestroyBmp = false;
3815 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3816
3817 if(!tex)
3818 {
3819 mustDestroyBmp = true;
3820 tex = create_bitmap_ex(8, tex_width, tex_height);
3821 clear_bitmap(tex);
3822 }
3823
3824 if(tile > 0) // TILE
3825 {
3826 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3827 }
3828 else // COMBO
3829 {
3830 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
3831 const int32_t tiletodraw = combo_tile(c, 0, 0);
3832 flip = flip ^ c.flip;
3833
3834 if(!(c.animflags & AF_EDITOR_ONLY))
3835 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3836 }
3837
3838 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3839 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3840 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3841 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
3842
3843 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
3844
3845 if(mustDestroyBmp)
3846 destroy_bitmap(tex);
3847
3848 }
3849
3850
3851
3852 void do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3853 {
3854 //sdci[1]=layer
3855 //sdci[2]=pos[9]
3856 //sdci[3]=uv[6]
3857 //sdci[4]=color[3]
3858 //sdci[5]=size[2]
3859 //sdci[6]=flip
3860 //sdci[7]=tile/combo
3861 //sdci[8]=polytype
3862
3863 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3864
3865 if(!v_ptr)
3866 {
3867 al_trace("Triange3d: Vector pointer is null! Internal error. \n");
3868 return;
3869 }
3870
3871 std::vector<int32_t> &v = *v_ptr;
3872
3873 if(v.empty())
3874 return;
3875
3876 int32_t* pos = &v[0];
3877 int32_t* uv = &v[9];
3878 int32_t* col = &v[15];
3879 int32_t* size = &v[18];
3880
3881 int32_t w = size[0]; //magic numerical constants... yuck.
3882 int32_t h = size[1];
3883 int32_t flip = (sdci[6]/10000)&3;
3884 int32_t tile = sdci[7]/10000;
3885 int32_t polytype = sdci[8]/10000;
3886
3887 polytype = vbound(polytype, 0, 14);
3888
3889 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3890 {
3891 Z_message("Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3892 return; //non power of two error
3893 }
3894
3895 int32_t tex_width = w*16;
3896 int32_t tex_height = h*16;
3897
3898 bool mustDestroyBmp = false;
3899 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3900
3901 if(!tex)
3902 {
3903 mustDestroyBmp = true;
3904 tex = create_bitmap_ex(8, tex_width, tex_height);
3905 clear_bitmap(tex);
3906 }
3907
3908 if(tile > 0) // TILE
3909 {
3910 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3911 }
3912 else // COMBO
3913 {
3914 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
3915 const int32_t tiletodraw = combo_tile(c, 0, 0);
3916 flip = flip ^ c.flip;
3917
3918 if(!(c.animflags & AF_EDITOR_ONLY))
3919 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3920 }
3921
3922 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3923 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3924 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3925
3926 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
3927
3928 if(mustDestroyBmp)
3929 destroy_bitmap(tex);
3930
3931 }
3932
3933 7971 void bmp_do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3934 {
3935 //Z_scripterrlog("rect sdci[13] is: %d\n", sdci[13]);
3936 //sdci[1]=layer
3937 //sdci[2]=x
3938 //sdci[3]=y
3939 //sdci[4]=x2
3940 //sdci[5]=y2
3941 //sdci[6]=color
3942 //sdci[7]=scale factor
3943 //sdci[8]=rotation anchor x
3944 //sdci[9]=rotation anchor y
3945 //sdci[10]=rotation angle
3946 //sdci[11]=fill
3947 //sdci[12]=opacity
3948 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
3949
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7]==0) //scale
3950 {
3951 return;
3952 }
3953
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7971 times.
7971 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
3954 {
3955 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
3956 return;
3957 }
3958 7971 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
3959
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if ( refbmp == NULL ) return;
3960
3961
2/4
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7971 times.
7971 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
3962
3963 7971 int32_t x1=sdci[2]/10000;
3964 7971 int32_t y1=sdci[3]/10000;
3965 7971 int32_t x2=sdci[4]/10000;
3966 7971 int32_t y2=sdci[5]/10000;
3967
3968
3969
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(x1>x2)
3970 {
3971 4 zc_swap(x1,x2);
3972 4 }
3973
3974
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(y1>y2)
3975 {
3976 4 zc_swap(y1,y2);
3977 4 }
3978
3979
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7] != 10000)
3980 {
3981 int32_t w=x2-x1+1;
3982 int32_t h=y2-y1+1;
3983 int32_t w2=(w*sdci[7])/10000;
3984 int32_t h2=(h*sdci[7])/10000;
3985 x1=x1-((w2-w)/2);
3986 x2=x2+((w2-w)/2);
3987 y1=y1-((h2-h)/2);
3988 y2=y2+((h2-h)/2);
3989 }
3990
3991 7971 int32_t color=sdci[6]/10000;
3992
3993
2/2
✓ Branch 0 taken 7843 times.
✓ Branch 1 taken 128 times.
7971 if(sdci[12]/10000<=127) //translucent
3994 {
3995 128 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
3996 128 }
3997
3998
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 7875 times.
7971 if(sdci[10]==0) //no rotation
3999 {
4000
2/2
✓ Branch 0 taken 7863 times.
✓ Branch 1 taken 12 times.
7875 if(sdci[11]) //filled
4001 {
4002 7863 rectfill(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4003 7863 }
4004 else //outline
4005 {
4006 12 rect(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4007 }
4008 7875 }
4009 else //rotate
4010 {
4011 int32_t xy[16];
4012 96 int32_t rx=sdci[8]/10000;
4013 96 int32_t ry=sdci[9]/10000;
4014 96 fixed ra1=itofix(sdci[10]%10000)/10000;
4015 96 fixed ra2=itofix(sdci[10]/10000);
4016 96 fixed ra=ra1+ra2;
4017 96 ra = (ra/360)*256;
4018
4019 96 fixed fcosa = fixcos(ra);
4020 96 fixed fsina = fixsin(ra);
4021
4022 96 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
4023 96 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
4024 96 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
4025 96 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
4026 96 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
4027 96 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
4028 96 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
4029 96 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
4030 96 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
4031 96 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
4032 96 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
4033 96 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
4034 96 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
4035 96 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
4036 96 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
4037 96 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
4038
4039
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(sdci[11]) //filled
4040 {
4041 96 polygon(refbmp, 4, xy, color);
4042 96 }
4043 else //outline
4044 {
4045 line(refbmp, xy[0], xy[1], xy[10], xy[11], color);
4046 line(refbmp, xy[2], xy[3], xy[12], xy[13], color);
4047 line(refbmp, xy[4], xy[5], xy[14], xy[15], color);
4048 line(refbmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
4049 }
4050 }
4051
4052 7971 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4053 7971 }
4054
4055 void bmp_do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4056 {
4057 //sdci[1]=layer
4058 //sdci[2]=x
4059 //sdci[3]=y
4060 //sdci[4]=tile
4061 //sdci[5]=cset
4062 //sdci[6]=width
4063 //sdci[7]=height
4064 //sdci[8]=overlay
4065 //sdci[9]=opacity
4066
4067 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4068 {
4069 Z_scripterrlog("bitmap->DrawFrame() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4070 return;
4071 }
4072 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4073 if ( refbmp == NULL ) return;
4074
4075 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4076
4077 int32_t x=sdci[2]/10000;
4078 int32_t y=sdci[3]/10000;
4079
4080 int32_t tile=sdci[4]/10000;
4081 int32_t cs=sdci[5]/10000;
4082 int32_t w=sdci[6]/10000;
4083 int32_t h=sdci[7]/10000;
4084 bool overlay=sdci[8];
4085 bool trans=(sdci[9]/10000<=127);
4086
4087 frame2x2(refbmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
4088 }
4089
4090
4091 148823 void bmp_do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4092 {
4093 //sdci[1]=layer
4094 //sdci[2]=x
4095 //sdci[3]=y
4096 //sdci[4]=radius
4097 //sdci[5]=color
4098 //sdci[6]=scale factor
4099 //sdci[7]=rotation anchor x
4100 //sdci[8]=rotation anchor y
4101 //sdci[9]=rotation angle
4102 //sdci[10]=fill
4103 //sdci[11]=opacity
4104 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4105
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6]==0) //scale
4106 {
4107 return;
4108 }
4109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
148823 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4110 {
4111 Z_scripterrlog("bitmap->Circle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4112 return;
4113 }
4114 148823 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4115
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if ( refbmp == NULL ) return;
4116
4117
2/4
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 148823 times.
148823 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4118
4119 148823 int32_t x1=sdci[2]/10000;
4120 148823 int32_t y1=sdci[3]/10000;
4121 148823 qword r=sdci[4];
4122
4123
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6] != 10000)
4124 {
4125 r*=sdci[6];
4126 r/=10000;
4127 }
4128
4129 148823 r/=10000;
4130 148823 int32_t color=sdci[5]/10000;
4131
4132
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[11]/10000<=127) //translucent
4133 {
4134 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4135 }
4136
4137
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
148823 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
4138 {
4139 int32_t xy[2];
4140 int32_t rx=sdci[7]/10000;
4141 int32_t ry=sdci[8]/10000;
4142 fixed ra1=itofix(sdci[9]%10000)/10000;
4143 fixed ra2=itofix(sdci[9]/10000);
4144 fixed ra=ra1+ra2;
4145 ra = (ra/360)*256;
4146
4147 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4148 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4149 x1=xy[0];
4150 y1=xy[1];
4151 }
4152
4153
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[10]) //filled
4154 {
4155 148823 circlefill(refbmp, x1+xoffset, y1+yoffset, r, color);
4156 148823 }
4157 else //outline
4158 {
4159 circle(refbmp, x1+xoffset, y1+yoffset, r, color);
4160 }
4161
4162 148823 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4163 148823 }
4164
4165
4166 void bmp_do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4167 {
4168 //sdci[1]=layer
4169 //sdci[2]=x
4170 //sdci[3]=y
4171 //sdci[4]=radius
4172 //sdci[5]=start angle
4173 //sdci[6]=end angle
4174 //sdci[7]=color
4175 //sdci[8]=scale factor
4176 //sdci[9]=rotation anchor x
4177 //sdci[10]=rotation anchor y
4178 //sdci[11]=rotation angle
4179 //sdci[12]=closed
4180 //sdci[13]=fill
4181 //sdci[14]=opacity
4182 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4183
4184 if(sdci[8]==0) //scale
4185 {
4186 return;
4187 }
4188 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4189 {
4190 Z_scripterrlog("bitmap->Arc() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4191 return;
4192 }
4193 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4194 if ( refbmp == NULL ) return;
4195
4196 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4197
4198 int32_t cx=sdci[2]/10000;
4199 int32_t cy=sdci[3]/10000;
4200 qword r=sdci[4];
4201
4202 if(sdci[8] != 10000)
4203 {
4204 r*=sdci[8];
4205 r/=10000;
4206 }
4207
4208 r/=10000;
4209
4210 int32_t color=sdci[7]/10000;
4211
4212 fixed ra1=itofix(sdci[11]%10000)/10000;
4213 fixed ra2=itofix(sdci[11]/10000);
4214 fixed ra=ra1+ra2;
4215 ra = (ra/360)*256;
4216
4217
4218 fixed a1=itofix(sdci[5]%10000)/10000;
4219 fixed a2=itofix(sdci[5]/10000);
4220 fixed sa=a1+a2;
4221 sa = (sa/360)*256;
4222
4223 a1=itofix(sdci[6]%10000)/10000;
4224 a2=itofix(sdci[6]/10000);
4225 fixed ea=a1+a2;
4226 ea = (ea/360)*256;
4227
4228 if(sdci[11]!=0) //rotation
4229 {
4230 int32_t rx=sdci[9]/10000;
4231 int32_t ry=sdci[10]/10000;
4232
4233 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
4234 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
4235 ea-=ra;
4236 sa-=ra;
4237 }
4238
4239 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
4240 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
4241
4242 if(sdci[12]) //closed
4243 {
4244 if(sdci[13]) //filled
4245 {
4246 clear_bitmap(prim_bmp);
4247 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4248 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4249 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4250 int fillx = zc_max(0,fx)+xoffset;
4251 int filly = zc_max(0,fy)+yoffset;
4252 zprint2("bitmap->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
4253 floodfill(prim_bmp, fillx, filly, color);
4254
4255 if(sdci[14]/10000<=127) //translucent
4256 {
4257 draw_trans_sprite(refbmp, prim_bmp, 0,0);
4258 }
4259 else
4260 {
4261 draw_sprite(refbmp, prim_bmp, 0,0);
4262 }
4263 }
4264 else
4265 {
4266 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4267 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4268 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4269 }
4270 }
4271 else
4272 {
4273 if(sdci[14]/10000<=127) //translucent
4274 {
4275 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4276 }
4277
4278 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4279 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4280 }
4281 }
4282
4283
4284 502 void bmp_do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4285 {
4286 //sdci[1]=layer
4287 //sdci[2]=x
4288 //sdci[3]=y
4289 //sdci[4]=radiusx
4290 //sdci[5]=radiusy
4291 //sdci[6]=color
4292 //sdci[7]=scale factor
4293 //sdci[8]=rotation anchor x
4294 //sdci[9]=rotation anchor y
4295 //sdci[10]=rotation angle
4296 //sdci[11]=fill
4297 //sdci[12]=opacity
4298 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4299
4300
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if(sdci[7]==0) //scale
4301 {
4302 return;
4303 }
4304
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 502 times.
502 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4305 {
4306 Z_scripterrlog("bitmap->Ellipse() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4307 return;
4308 }
4309 502 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4310
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if ( refbmp == NULL ) return;
4311
4312 502 int32_t x1=sdci[2]/10000;
4313 502 int32_t y1=sdci[3]/10000;
4314 502 int32_t radx=sdci[4]/10000;
4315 502 radx*=sdci[7]/10000;
4316 502 int32_t rady=sdci[5]/10000;
4317 502 rady*=sdci[7]/10000;
4318 502 int32_t color=sdci[6]/10000;
4319 502 float rotation = sdci[10]/10000;
4320
4321 502 int32_t rx=sdci[8]/10000;
4322 502 int32_t ry=sdci[9]/10000;
4323 502 fixed ra1=itofix(sdci[10]%10000)/10000;
4324 502 fixed ra2=itofix(sdci[10]/10000);
4325 502 fixed ra=ra1+ra2;
4326 502 ra = (ra/360)*256;
4327
4328
2/4
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 502 times.
✗ Branch 3 not taken.
502 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4329
4330 int32_t xy[2];
4331 502 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4332 502 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4333 502 x1=xy[0];
4334 502 y1=xy[1];
4335
4336
6/8
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 494 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 494 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 494 times.
502 if(radx<1||rady<1||radx>255||rady>255) return;
4337
4338 494 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
4339
4340
2/4
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 494 times.
494 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4341
4342
1/2
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
494 if(sdci[11]) //filled
4343 {
4344
4345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 494 times.
494 if(sdci[12]/10000<128) //translucent
4346 {
4347 clear_bitmap(prim_bmp);
4348 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4349 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4350 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4351 }
4352 else // no opacity
4353 {
4354
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4355 494 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4356 }
4357 494 }
4358 else //not filled
4359 {
4360 if(sdci[12]/10000<128) //translucent
4361 {
4362 clear_bitmap(prim_bmp);
4363 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4364 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4365 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4366 }
4367 else // no opacity
4368 {
4369 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4370 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4371 }
4372 }
4373
4374 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
4375 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
4376 // the ellipse, but it shouldn't be used anyway.
4377
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 if(color==0)
4378 {
4379 // This is very slow, so check the smallest possible square
4380
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
4381
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
4382
4383
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 60 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4430 times.
✓ Branch 7 taken 62 times.
4492 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
4384
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 4430 times.
✓ Branch 2 taken 1086 times.
✓ Branch 3 taken 3344 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1086 times.
✓ Branch 6 taken 467774 times.
✓ Branch 7 taken 4430 times.
472204 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
4385
2/2
✓ Branch 0 taken 238992 times.
✓ Branch 1 taken 228782 times.
696556 if(getpixel(refbmp, x, y)==255)
4386 233212 putpixel(refbmp, x, y, 0);
4387 62 }
4388
4389 494 script_drawing_commands.ReleaseSubBitmap(bitty);
4390 502 }
4391
4392
4393 144 void bmp_do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4394 {
4395 //sdci[1]=layer
4396 //sdci[2]=x
4397 //sdci[3]=y
4398 //sdci[4]=x2
4399 //sdci[5]=y2
4400 //sdci[6]=color
4401 //sdci[7]=scale factor
4402 //sdci[8]=rotation anchor x
4403 //sdci[9]=rotation anchor y
4404 //sdci[10]=rotation angle
4405 //sdci[11]=opacity
4406 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4407
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7]==0) //scale
4408 {
4409 return;
4410 }
4411
4412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 144 times.
144 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4413 {
4414 Z_scripterrlog("bitmap->Line() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4415 return;
4416 }
4417
4418 144 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4419
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if ( refbmp == NULL ) return;
4420
4421 144 int32_t x1=sdci[2]/10000;
4422 144 int32_t y1=sdci[3]/10000;
4423 144 int32_t x2=sdci[4]/10000;
4424 144 int32_t y2=sdci[5]/10000;
4425
4426
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7] != 10000)
4427 {
4428 int32_t w=x2-x1+1;
4429 int32_t h=y2-y1+1;
4430 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
4431 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
4432 x1=x1-((w2-w)/2);
4433 x2=x2+((w2-w)/2);
4434 y1=y1-((h2-h)/2);
4435 y2=y2+((h2-h)/2);
4436 }
4437
4438 144 int32_t color=sdci[6]/10000;
4439
4440
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
144 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4441
4442
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[11]/10000<=127) //translucent
4443 {
4444 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4445 }
4446
4447
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[10]!=0) //rotation
4448 {
4449 int32_t xy[4];
4450 int32_t rx=sdci[8]/10000;
4451 int32_t ry=sdci[9]/10000;
4452 fixed ra1=itofix(sdci[10]%10000)/10000;
4453 fixed ra2=itofix(sdci[10]/10000);
4454 fixed ra=ra1+ra2;
4455
4456 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4457 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4458 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
4459 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
4460 x1=xy[0];
4461 y1=xy[1];
4462 x2=xy[2];
4463 y2=xy[3];
4464 }
4465
4466 144 line(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4467 144 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4468 144 }
4469
4470
4471 void bmp_do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4472 {
4473 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
4474 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4475
4476 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
4477 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
4478 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
4479 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
4480 };
4481
4482 if(sdci[11]/10000 < 128) //translucent
4483 {
4484 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4485 }
4486
4487 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4488 {
4489 Z_scripterrlog("bitmap->Spline() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4490 return;
4491 }
4492
4493 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4494 if ( refbmp == NULL ) return;
4495
4496 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4497
4498 spline(refbmp, points, sdci[10]/10000);
4499
4500 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4501 }
4502
4503
4504 80910 void bmp_do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4505 {
4506 //sdci[1]=layer
4507 //sdci[2]=x
4508 //sdci[3]=y
4509 //sdci[4]=color
4510 //sdci[5]=rotation anchor x
4511 //sdci[6]=rotation anchor y
4512 //sdci[7]=rotation angle
4513 //sdci[8]=opacity
4514 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4515 80910 int32_t x1=sdci[2]/10000;
4516 80910 int32_t y1=sdci[3]/10000;
4517 80910 int32_t color=sdci[4]/10000;
4518
4519
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if(sdci[8]/10000<=127) //translucent
4520 {
4521 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4522 }
4523
4524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4525 {
4526 Z_scripterrlog("bitmap->PutPixel() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4527 return;
4528 }
4529
4530 80910 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4531
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if ( refbmp == NULL ) return;
4532
4533
2/4
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80910 times.
✗ Branch 3 not taken.
80910 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4534
4535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if(sdci[7]!=0) //rotation
4536 {
4537 int32_t xy[2];
4538 int32_t rx=sdci[5]/10000;
4539 int32_t ry=sdci[6]/10000;
4540 fixed ra1=itofix(sdci[7]%10000)/10000;
4541 fixed ra2=itofix(sdci[7]/10000);
4542 fixed ra=ra1+ra2;
4543
4544 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4545 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4546 x1=xy[0];
4547 y1=xy[1];
4548 }
4549
4550 80910 putpixel(refbmp, x1+xoffset, y1+yoffset, color);
4551 80910 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4552 80910 }
4553
4554
4555 59816 void bmp_do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4556 {
4557 //sdci[1]=layer
4558 //sdci[2]=x
4559 //sdci[3]=y
4560 //sdci[4]=tile
4561 //sdci[5]=tile width
4562 //sdci[6]=tile height
4563 //sdci[7]=color (cset)
4564 //sdci[8]=scale x
4565 //sdci[9]=scale y
4566 //sdci[10]=rotation anchor x
4567 //sdci[11]=rotation anchor y
4568 //sdci[12]=rotation angle
4569 //sdci[13]=flip
4570 //sdci[14]=transparency
4571 //sdci[15]=opacity
4572 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4573
4574 59816 int32_t w = sdci[5]/10000;
4575 59816 int32_t h = sdci[6]/10000;
4576
4577
4/8
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59816 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 59816 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 59816 times.
59816 if(w < 1 || h < 1 || h > 20 || w > 20)
4578 {
4579 return;
4580 }
4581
4582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4583 {
4584 Z_scripterrlog("bitmap->DrawTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4585 return;
4586 }
4587
4588 59816 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4589
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( refbmp == NULL ) return;
4590
4591 59816 int32_t xscale=sdci[8]/10000;
4592 59816 int32_t yscale=sdci[9]/10000;
4593 59816 int32_t rx = sdci[10]/10000;
4594 59816 int32_t ry = sdci[11]/10000;
4595 59816 float rotation=sdci[12]/10000;
4596 59816 int32_t flip=(sdci[13]/10000)&3;
4597 59816 bool transparency=sdci[14]!=0;
4598 59816 int32_t opacity=sdci[15]/10000;
4599 59816 int32_t color=sdci[7]/10000;
4600
4601 59816 int32_t x1=sdci[2]/10000;
4602 59816 int32_t y1=sdci[3]/10000;
4603
4604
4605 //don't scale if it's not safe to do so
4606 59816 bool canscale = true;
4607
4608
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if(xscale==0||yscale==0)
4609 {
4610 return;
4611 }
4612
4613
3/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 906 times.
✗ Branch 3 not taken.
59816 if(xscale<0||yscale<0)
4614 58910 canscale = false; //default size
4615
4616
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4617
4618
4/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 4608 times.
✓ Branch 3 taken 54302 times.
59816 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4619 {
4620 5514 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
4621
4622
1/2
✓ Branch 0 taken 5514 times.
✗ Branch 1 not taken.
5514 if(transparency) //transparency
4623 {
4624 5514 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4625 5514 }
4626 else //no transparency
4627 {
4628 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4629 }
4630
4631
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 906 times.
5514 if(rotation != 0)
4632 {
4633 //low negative values indicate no anchor-point rotation
4634
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4608 if(rx>-777||ry>-777)
4635 {
4636 int32_t xy[2];
4637 4608 fixed ra1=itofix(sdci[12]%10000)/10000;
4638 4608 fixed ra2=itofix(sdci[12]/10000);
4639 4608 fixed ra=ra1+ra2;
4640 4608 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4641 4608 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4642 4608 x1=xy[0];
4643 4608 y1=xy[1];
4644 4608 }
4645
4646
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(canscale) //scale first
4647 {
4648 //damnit all, .. fixme.
4649 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4650 clear_bitmap(tempbit);
4651
4652 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4653
4654 if(opacity < 128)
4655 {
4656 clear_bitmap(prim_bmp);
4657 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4658 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
4659 }
4660 else
4661 {
4662 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4663 }
4664
4665 destroy_bitmap(tempbit);
4666 }
4667 else //no scale
4668 {
4669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(opacity < 128)
4670 {
4671 clear_bitmap(prim_bmp);
4672 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4673 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4674 }
4675 else
4676 {
4677 4608 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4678 }
4679 }
4680 4608 }
4681 else //scale only
4682 {
4683
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if(canscale)
4684 {
4685
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(opacity<128)
4686 {
4687 clear_bitmap(prim_bmp);
4688 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4689 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4690 }
4691 else
4692 {
4693 906 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4694 }
4695 906 }
4696 else //error -do not scale
4697 {
4698 if(opacity<128)
4699 {
4700 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4701 }
4702 else
4703 {
4704 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4705 }
4706 }
4707 }
4708
4709 5514 script_drawing_commands.ReleaseSubBitmap(pbitty);
4710
4711 5514 }
4712 else // no scale or rotation
4713 {
4714
2/2
✓ Branch 0 taken 45964 times.
✓ Branch 1 taken 8338 times.
54302 if(transparency)
4715 {
4716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45964 times.
45964 if(opacity<=127)
4717 TileHelper::OverTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4718 else
4719 45964 TileHelper::OverTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4720 45964 }
4721 else
4722 {
4723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8338 times.
8338 if(opacity<=127)
4724 TileHelper::PutTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4725 else
4726 8338 TileHelper::OldPutTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4727 }
4728 }
4729 59816 }
4730
4731 void bmp_do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4732 {
4733 //sdci[1]=layer
4734 //sdci[2]=x
4735 //sdci[3]=y
4736 //sdci[4]=tile
4737 //sdci[5]=tile width
4738 //sdci[6]=tile height
4739 //sdci[7]=flip
4740 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4741
4742 int32_t w = sdci[5]/10000;
4743 int32_t h = sdci[6]/10000;
4744
4745 if(w < 1 || h < 1 || h > 20 || w > 20)
4746 {
4747 return;
4748 }
4749
4750 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4751 {
4752 Z_scripterrlog("bitmap->DrawTileCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4753 return;
4754 }
4755
4756 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4757 if ( refbmp == NULL ) return;
4758
4759 int32_t flip=(sdci[7]/10000)&3;
4760
4761 int32_t x1=sdci[2]/10000;
4762 int32_t y1=sdci[3]/10000;
4763
4764 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4765
4766 TileHelper::OverTileCloaked(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
4767 }
4768
4769
4770 824 void bmp_do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4771 {
4772 //sdci[1]=layer
4773 //sdci[2]=x
4774 //sdci[3]=y
4775 //sdci[4]=combo
4776 //sdci[5]=tile width
4777 //sdci[6]=tile height
4778 //sdci[7]=color (cset)
4779 //sdci[8]=scale x
4780 //sdci[9]=scale y
4781 //sdci[10]=rotation anchor x
4782 //sdci[11]=rotation anchor y
4783 //sdci[12]=rotation angle
4784 //sdci[13]=frame
4785 //sdci[14]=flip
4786 //sdci[15]=transparency
4787 //sdci[16]=opacity
4788 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4789 824 int32_t w = sdci[5]/10000;
4790 824 int32_t h = sdci[6]/10000;
4791
4792
4/8
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 824 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 824 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 824 times.
824 if(w<1||h<1||h>20||w>20)
4793 {
4794 return;
4795 }
4796
4797
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4798 {
4799 Z_scripterrlog("bitmap->DrawCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4800 return;
4801 }
4802
4803 824 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4804
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if ( refbmp == NULL ) return;
4805 824 int32_t cmb = (sdci[4]/10000);
4806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if((unsigned)cmb >= MAXCOMBOS)
4807 {
4808 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4809 return;
4810 }
4811
4812 824 int32_t xscale=sdci[8]/10000;
4813 824 int32_t yscale=sdci[9]/10000;
4814 824 int32_t rx = sdci[10]/10000; //these work now
4815 824 int32_t ry = sdci[11]/10000; //these work now
4816 824 float rotation=sdci[12]/10000;
4817
4818 824 bool transparency=sdci[15]!=0;
4819 824 int32_t opacity=sdci[16]/10000;
4820 824 int32_t color=sdci[7]/10000;
4821 824 int32_t x1=sdci[2]/10000;
4822 824 int32_t y1=sdci[3]/10000;
4823
4824 824 auto& c = GET_DRAWING_COMBO(cmb);
4825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if(c.animflags & AF_EDITOR_ONLY) return;
4826 824 int32_t tiletodraw = combo_tile(c, x1, y1);
4827 824 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
4828 824 int32_t skiprows=c.skipanimy;
4829
4830
4831 //don't scale if it's not safe to do so
4832 824 bool canscale = true;
4833
4834
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if(xscale==0||yscale==0)
4835 {
4836 return;
4837 }
4838
4839
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
824 if(xscale<0||yscale<0)
4840 824 canscale = false; //default size
4841
4842
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4843
4844
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4845 {
4846 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
4847
4848 if(transparency)
4849 {
4850 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4851 }
4852 else //no transparency
4853 {
4854 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4855 }
4856
4857 if(rotation != 0) // rotate
4858 {
4859 //fixed point sucks ;0
4860 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
4861 {
4862 int32_t xy[2];
4863 fixed ra1=itofix(sdci[12]%10000)/10000;
4864 fixed ra2=itofix(sdci[12]/10000);
4865 fixed ra=ra1+ra2;
4866 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4867 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4868 x1=xy[0];
4869 y1=xy[1];
4870 }
4871
4872 if(canscale) //scale first
4873 {
4874 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4875 clear_bitmap(tempbit);
4876
4877 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4878
4879 if(opacity < 128)
4880 {
4881 clear_bitmap(prim_bmp);
4882 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4883 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4884 }
4885 else
4886 {
4887 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4888 }
4889
4890 destroy_bitmap(tempbit);
4891 }
4892 else //no scale
4893 {
4894 if(opacity < 128)
4895 {
4896 clear_bitmap(prim_bmp);
4897 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4898 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4899 }
4900 else
4901 {
4902 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4903 }
4904 }
4905 }
4906 else //scale only
4907 {
4908 if(canscale)
4909 {
4910 if(opacity<128)
4911 {
4912 clear_bitmap(prim_bmp);
4913 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4914 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4915 }
4916 else
4917 {
4918 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4919 }
4920 }
4921 else //error -do not scale
4922 {
4923 if(opacity<128)
4924 {
4925 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4926 }
4927 else
4928 {
4929 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4930 }
4931 }
4932 }
4933
4934 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
4935 }
4936 else // no scale or rotation
4937 {
4938
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if(transparency)
4939 {
4940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if(opacity<=127)
4941 TileHelper::OverTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4942 else
4943 824 TileHelper::OverTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4944 824 }
4945 else
4946 {
4947 if(opacity<=127)
4948 TileHelper::PutTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4949 else
4950 TileHelper::OldPutTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4951 }
4952 }
4953 824 }
4954
4955
4956 void bmp_do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4957 {
4958 //sdci[1]=layer
4959 //sdci[2]=x
4960 //sdci[3]=y
4961 //sdci[4]=combo
4962 //sdci[5]=tile width
4963 //sdci[6]=tile height
4964 //sdci[7]=flip
4965 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4966
4967 int32_t w = sdci[5]/10000;
4968 int32_t h = sdci[6]/10000;
4969
4970 if(w<1||h<1||h>20||w>20)
4971 {
4972 return;
4973 }
4974
4975 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4976 {
4977 Z_scripterrlog("bitmap->DrawComboCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4978 return;
4979 }
4980
4981 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
4982 if ( refbmp == NULL ) return;
4983 int32_t cmb = (sdci[4]/10000);
4984 if((unsigned)cmb >= MAXCOMBOS)
4985 {
4986 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4987 return;
4988 }
4989
4990 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4991
4992 int32_t x1=sdci[2]/10000;
4993 int32_t y1=sdci[3]/10000;
4994
4995 auto& c = GET_DRAWING_COMBO(cmb);
4996 if(c.animflags & AF_EDITOR_ONLY) return;
4997 int32_t tiletodraw = combo_tile(c, x1, y1);
4998 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
4999 int32_t skiprows=c.skipanimy;
5000
5001 TileHelper::OverTileCloaked(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
5002 }
5003
5004
5005 168443 void bmp_do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5006 {
5007 /* layer, x, y, tile, color opacity */
5008 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5009
5010 168443 int32_t opacity = sdci[6]/10000;
5011
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168443 times.
168443 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5012 {
5013 Z_scripterrlog("bitmap->FastTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5014 return;
5015 }
5016 168443 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5017
1/2
✓ Branch 0 taken 168443 times.
✗ Branch 1 not taken.
168443 if ( refbmp == NULL ) return;
5018
5019
2/4
✓ Branch 0 taken 168443 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 168443 times.
✗ Branch 3 not taken.
168443 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5020
5021 168443 int x = xoffset+(sdci[2]/10000);
5022 168443 int y = yoffset+(sdci[3]/10000);
5023
5024
2/2
✓ Branch 0 taken 11131 times.
✓ Branch 1 taken 157312 times.
168443 if(opacity < 128)
5025 11131 overtiletranslucent16(refbmp, sdci[4]/10000, x, y, sdci[5]/10000, 0, opacity);
5026 else
5027 157312 overtile16(refbmp, sdci[4]/10000, x, y, sdci[5]/10000, 0);
5028 168443 }
5029
5030 19821648 void do_bmpwritetile(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5031 {
5032 /* layer, x, y, tile, is8bit, mask */
5033 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5034
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19821648 times.
19821648 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5035 {
5036 Z_scripterrlog("bitmap->WriteTile() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5037 return;
5038 }
5039 19821648 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5040
1/2
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
19821648 if ( refbmp == NULL ) return;
5041
5042
2/4
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19821648 times.
✗ Branch 3 not taken.
19821648 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5043
5044 19821648 int32_t x = (sdci[2]/10000), y = (sdci[3]/10000), tl = (sdci[4]/10000);
5045 19821648 bool is8bit = sdci[5]!=0, mask = sdci[6]!=0;
5046
5047 19821648 write_tile(newtilebuf, refbmp, tl, x+xoffset, y+yoffset, is8bit, mask);
5048 19821648 }
5049
5050 void do_bmpdither(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5051 {
5052 /* layer, mask, color, ditherType, ditherArg */
5053 //sdci[2] Mask Bitmap Pointer
5054 //sdci[3] Color
5055 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5056 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5057 {
5058 Z_scripterrlog("bitmap->Dither() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5059 return;
5060 }
5061 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5062 if ( refbmp == NULL ) return;
5063 if ( sdci[2] <= 0 )
5064 {
5065 Z_scripterrlog("bitmap->Dither() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5066 return;
5067 }
5068 BITMAP *mask = resolveScriptingBitmap(sdci[2]);
5069 if ( mask == NULL ) return;
5070
5071 int32_t dType = sdci[4] / 10000L;
5072 if(dType < 0 || dType >= dithMax)
5073 {
5074 Z_scripterrlog("bitmap->Dither() used an invalid dither type: %d. Aborting.\n", dType);
5075 return;
5076 }
5077
5078 ditherblit(refbmp, mask, byte(sdci[3]/10000L), dType, sdci[5]/10000L);
5079 }
5080
5081 7323 void do_bmpreplcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5082 {
5083 /* layer, shift, startcol, endcol */
5084 //sdci[2] NewCol
5085 //sdci[3] StartCol
5086 //sdci[4] EndCol
5087 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7323 times.
7323 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5089 {
5090 Z_scripterrlog("bitmap->ReplaceColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5091 return;
5092 }
5093 7323 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5094
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7323 times.
7323 if ( refbmp == NULL ) return;
5095 7323 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, false);
5096 7323 }
5097
5098 void do_bmpshiftcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5099 {
5100 /* layer, shift, startcol, endcol */
5101 //sdci[2] ShiftAmount
5102 //sdci[3] StartCol
5103 //sdci[4] EndCol
5104 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5105 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5106 {
5107 Z_scripterrlog("bitmap->ShiftColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5108 return;
5109 }
5110 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5111 if ( refbmp == NULL ) return;
5112 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, true);
5113 }
5114
5115 906 void do_bmpmaskdraw(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5116 {
5117 /* layer, mask, color */
5118 //sdci[2] Mask Bitmap Pointer
5119 //sdci[3] Color
5120 //sdci[4] start mask color
5121 //sdci[5] end mask color
5122 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5123 906 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5124
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( refbmp == NULL )
5125 {
5126 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5127 return;
5128 }
5129 906 BITMAP *mask = resolveScriptingBitmap(sdci[2]);
5130
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( mask == NULL )
5131 {
5132 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5133 return;
5134 }
5135 906 auto fillcol = sdci[3]/10000L;
5136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(unsigned(fillcol) > 0xFF) return; //invalid color, nothing to draw
5137 906 auto startcol = vbound(sdci[4]/10000L,0x00,0xFF);
5138 906 auto endcol = vbound(sdci[5]/10000L,0x00,0xFF);
5139 906 mask_colorfill(refbmp, mask, fillcol, startcol, endcol);
5140 906 }
5141
5142 void do_bmpmaskblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5143 {
5144 /* layer, mask, color */
5145 //sdci[2] Mask Bitmap Pointer
5146 //sdci[3] Pattern Bitmap
5147 //sdci[4] bool 'pattern repeats'
5148 //sdci[5] start mask color
5149 //sdci[6] end mask color
5150 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5151 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5152 if ( refbmp == NULL )
5153 {
5154 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5155 return;
5156 }
5157 BITMAP *mask = resolveScriptingBitmap(sdci[2]);
5158 if ( mask == NULL )
5159 {
5160 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (mask) id: %d. Aborting.\n", sdci[2]);
5161 return;
5162 }
5163 BITMAP *pattern = resolveScriptingBitmap(sdci[3]);
5164 if ( pattern == NULL )
5165 {
5166 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (pattern) id: %d. Aborting.\n", sdci[3]);
5167 return;
5168 }
5169 bool repeats = sdci[4]!=0;
5170 auto startcol = vbound(sdci[5]/10000L,0x00,0xFF);
5171 auto endcol = vbound(sdci[6]/10000L,0x00,0xFF);
5172 mask_blit(refbmp, mask, pattern, repeats, startcol, endcol);
5173 }
5174
5175 32636464 void bmp_do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5176 {
5177 /* layer, x, y, tile, color opacity */
5178 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5179 32636464 int32_t opacity = sdci[6] / 10000;
5180 32636464 int32_t x1 = sdci[2] / 10000;
5181 32636464 int32_t y1 = sdci[3] / 10000;
5182 32636464 int32_t index = sdci[4]/10000;
5183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5184 {
5185 Z_scripterrlog("bitmap->FastCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5186 return;
5187 }
5188 32636464 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5189
1/2
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
32636464 if ( refbmp == NULL ) return;
5190 32636464 int32_t cmb = (sdci[4]/10000);
5191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if((unsigned)cmb >= MAXCOMBOS)
5192 {
5193 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
5194 return;
5195 }
5196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if(combobuf[cmb].animflags & AF_EDITOR_ONLY) return;
5197
5198
2/4
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32636464 times.
✗ Branch 3 not taken.
32636464 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5199
5200 32636464 int x = xoffset+x1;
5201 32636464 int y = yoffset+y1;
5202
5203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if(opacity < 128)
5204 {
5205 overcomboblocktranslucent(refbmp, x, y, cmb, sdci[5]/10000, 1, 1, 128);
5206
5207 }
5208 else
5209 {
5210 32636464 overcomboblock(refbmp, x, y, cmb, sdci[5]/10000, 1, 1);
5211 }
5212 32636464 }
5213
5214
5215
5216 void bmp_do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5217 {
5218 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5219 {
5220 Z_scripterrlog("bitmap->DrawCharacter() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5221 return;
5222 }
5223 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5224 if ( refbmp == NULL ) return;
5225
5226 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5227
5228 //broken 2.50.2 and earlier drawcharacter()
5229 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5230 {
5231 //sdci[1]=layer
5232 //sdci[2]=x
5233 //sdci[3]=y
5234 //sdci[4]=font
5235 //sdci[5]=color
5236 //sdci[6]=bg color
5237 //sdci[7]=strech x (width)
5238 //sdci[8]=stretch y (height)
5239 //sdci[9]=char
5240 //sdci[10]=opacity
5241 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5242
5243 int32_t x=sdci[2]/10000;
5244 int32_t y=sdci[3]/10000;
5245 int32_t font_index=sdci[4]/10000;
5246 int32_t color=sdci[5]/10000;
5247 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5248 int32_t w=sdci[7]/10000;
5249 int32_t h=sdci[8]/10000;
5250 char glyph=char(sdci[9]/10000);
5251 int32_t opacity=sdci[10]/10000;
5252
5253 //safe check
5254 if(bg_color < -1) bg_color = -1;
5255
5256 if(w>512) w=512; //w=vbound(w,0,512);
5257
5258 if(h>512) h=512; //h=vbound(h,0,512);
5259
5260 //undone
5261 if(w>0&&h>0)//stretch the character
5262 {
5263 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5264
5265 if(opacity < 128)
5266 {
5267 if(w>128||h>128)
5268 {
5269 clear_bitmap(prim_bmp);
5270
5271 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5272 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5273 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5274 }
5275 else //this is faster
5276 {
5277 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5278
5279 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5280 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5281 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5282
5283 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5284 }
5285 }
5286 else // no opacity
5287 {
5288 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5289 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5290 }
5291
5292 }
5293 else //no stretch
5294 {
5295 if(opacity < 128)
5296 {
5297 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5298 clear_bitmap(pbmp);
5299
5300 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5301 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5302
5303 destroy_bitmap(pbmp);
5304 }
5305 else // no opacity
5306 {
5307 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5308 }
5309 }
5310 }
5311
5312 else //2.53.0 fixed version and later.
5313 {
5314
5315 //sdci[1]=layer
5316 //sdci[2]=x
5317 //sdci[3]=y
5318 //sdci[4]=font
5319 //sdci[5]=color
5320 //sdci[6]=bg color
5321 //sdci[7]=strech x (width)
5322 //sdci[8]=stretch y (height)
5323 //sdci[9]=char
5324 //sdci[10]=opacity
5325
5326 int32_t x=sdci[2]/10000;
5327 int32_t y=sdci[3]/10000;
5328 int32_t font_index=sdci[4]/10000;
5329 int32_t color=sdci[5]/10000;
5330 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5331 int32_t w=sdci[7]/10000;
5332 int32_t h=sdci[8]/10000;
5333 char glyph=char(sdci[9]/10000);
5334 int32_t opacity=sdci[10]/10000;
5335
5336 //safe check
5337 if(bg_color < -1) bg_color = -1;
5338
5339 if(w>512) w=512; //w=vbound(w,0,512);
5340
5341 if(h>512) h=512; //h=vbound(h,0,512);
5342
5343 //undone
5344 if(w>0&&h>0)//stretch the character
5345 {
5346 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5347
5348 if(opacity < 128)
5349 {
5350 if(w>128||h>128)
5351 {
5352 clear_bitmap(prim_bmp);
5353
5354 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5355 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5356 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5357 }
5358 else //this is faster
5359 {
5360 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5361
5362 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5363 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5364 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5365
5366 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5367 }
5368 }
5369 else // no opacity
5370 {
5371 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5372 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5373 }
5374
5375 }
5376 else //no stretch
5377 {
5378 if(opacity < 128)
5379 {
5380 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5381 clear_bitmap(pbmp);
5382
5383 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5384 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5385
5386 destroy_bitmap(pbmp);
5387 }
5388 else // no opacity
5389 {
5390 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5391 }
5392 }
5393
5394 }
5395
5396 }
5397
5398
5399 void bmp_do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5400 {
5401 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5402 {
5403 Z_scripterrlog("bitmap->DrawInteger() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5404 return;
5405 }
5406 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5407 if ( refbmp == NULL ) return;
5408
5409 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5410
5411 //broken 2.50.2 and earlier drawinteger()
5412 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5413 {
5414 //sdci[1]=layer
5415 //sdci[2]=x
5416 //sdci[3]=y
5417 //sdci[4]=font
5418 //sdci[5]=color
5419 //sdci[6]=bg color
5420 //sdci[7]=strech x (width)
5421 //sdci[8]=stretch y (height)
5422 //sdci[9]=integer
5423 //sdci[10]=num decimal places
5424 //sdci[11]=opacity
5425 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5426
5427 int32_t x=sdci[2]/10000;
5428 int32_t y=sdci[3]/10000;
5429 int32_t font_index=sdci[4]/10000;
5430 int32_t color=sdci[5]/10000;
5431 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5432 int32_t w=sdci[7]/10000;
5433 int32_t h=sdci[8]/10000;
5434 int32_t decplace=sdci[10]/10000;
5435 int32_t opacity=sdci[11]/10000;
5436
5437 //safe check
5438 if(bg_color < -1) bg_color = -1;
5439
5440 if(w>512) w=512; //w=vbound(w,0,512);
5441
5442 if(h>512) h=512; //h=vbound(h,0,512);
5443
5444 char numbuf[15];
5445
5446 switch(decplace)
5447 {
5448 default:
5449 case 0:
5450 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5451 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5452
5453 case 1:
5454 //sprintf(numbuf,"%.01f",number);
5455 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5456 break;
5457
5458 case 2:
5459 //sprintf(numbuf,"%.02f",number);
5460 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5461 break;
5462
5463 case 3:
5464 //sprintf(numbuf,"%.03f",number);
5465 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5466 break;
5467
5468 case 4:
5469 //sprintf(numbuf,"%.04f",number);
5470 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5471 break;
5472 }
5473
5474 if(w>0&&h>0)//stretch
5475 {
5476 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5477
5478 if(opacity < 128)
5479 {
5480 if(w>128||h>128)
5481 {
5482 clear_bitmap(prim_bmp);
5483
5484 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5485 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5486 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5487 }
5488 else
5489 {
5490 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5491 clear_bitmap(pbmp2);
5492
5493 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5494 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5495 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5496
5497 destroy_bitmap(pbmp2);
5498 }
5499 }
5500 else // no opacity
5501 {
5502 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5503 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5504 }
5505
5506 }
5507 else //no stretch
5508 {
5509 if(opacity < 128)
5510 {
5511 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5512 clear_bitmap(pbmp);
5513
5514 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5515 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5516
5517 destroy_bitmap(pbmp);
5518 }
5519 else // no opacity
5520 {
5521 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5522 }
5523 }
5524
5525 }
5526
5527 else //2.53.0 fixed version and later.
5528 {
5529 //sdci[1]=layer
5530 //sdci[2]=x
5531 //sdci[3]=y
5532 //sdci[4]=font
5533 //sdci[5]=color
5534 //sdci[6]=bg color
5535 //sdci[7]=strech x (width)
5536 //sdci[8]=stretch y (height)
5537 //sdci[9]=integer
5538 //sdci[10]=num decimal places
5539 //sdci[11]=opacity
5540
5541 int32_t x=sdci[2]/10000;
5542 int32_t y=sdci[3]/10000;
5543 int32_t font_index=sdci[4]/10000;
5544 int32_t color=sdci[5]/10000;
5545 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5546 int32_t w=sdci[7]/10000;
5547 int32_t h=sdci[8]/10000;
5548 int32_t decplace=sdci[10]/10000;
5549 int32_t opacity=sdci[11]/10000;
5550
5551 //safe check
5552 if(bg_color < -1) bg_color = -1;
5553
5554 if(w>512) w=512; //w=vbound(w,0,512);
5555
5556 if(h>512) h=512; //h=vbound(h,0,512);
5557
5558 char numbuf[15];
5559
5560 switch(decplace)
5561 {
5562 default:
5563 case 0:
5564 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5565 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5566
5567 case 1:
5568 //sprintf(numbuf,"%.01f",number);
5569 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5570 break;
5571
5572 case 2:
5573 //sprintf(numbuf,"%.02f",number);
5574 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5575 break;
5576
5577 case 3:
5578 //sprintf(numbuf,"%.03f",number);
5579 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5580 break;
5581
5582 case 4:
5583 //sprintf(numbuf,"%.04f",number);
5584 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5585 break;
5586 }
5587
5588 //FONT* font=get_zc_font(sdci[4]/10000);
5589
5590 if(w>0&&h>0)//stretch
5591 {
5592 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
5593 clear_bitmap(pbmp);
5594 //script_drawing_commands.GetSmallTextureBitmap(1,1);
5595
5596 if(opacity < 128)
5597 {
5598 if(w>128||h>128)
5599 {
5600 clear_bitmap(prim_bmp);
5601
5602 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5603 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5604 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5605 }
5606 else
5607 {
5608 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5609 clear_bitmap(pbmp2);
5610
5611 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5612 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5613 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5614
5615 destroy_bitmap(pbmp2);
5616 }
5617 }
5618 else // no opacity
5619 {
5620 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5621 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5622 }
5623
5624 }
5625 else //no stretch
5626 {
5627 if(opacity < 128)
5628 {
5629 FONT* font = get_zc_font(font_index);
5630 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
5631 clear_bitmap(pbmp);
5632
5633 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
5634 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5635
5636 destroy_bitmap(pbmp);
5637 }
5638 else // no opacity
5639 {
5640 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5641 }
5642 }
5643 }
5644 }
5645
5646
5647 865 void bmp_do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5648 {
5649 //sdci[1]=layer
5650 //sdci[2]=x
5651 //sdci[3]=y
5652 //sdci[4]=font
5653 //sdci[5]=color
5654 //sdci[6]=bg color
5655 //sdci[7]=format_option
5656 //sdci[8]=string
5657 //sdci[9]=opacity
5658 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5659
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5660 {
5661 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5662 return;
5663 }
5664
5665 865 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5666
1/2
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
865 if ( refbmp == NULL ) return;
5667
5668
2/4
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 865 times.
865 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5669
5670 865 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5671
5672
1/2
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
865 if(!str)
5673 {
5674 al_trace("String pointer is null! Internal error. \n");
5675 return;
5676 }
5677
5678 865 int32_t x=sdci[2]/10000;
5679 865 int32_t y=sdci[3]/10000;
5680 865 FONT* font=get_zc_font(sdci[4]/10000);
5681 865 int32_t color=sdci[5]/10000;
5682 865 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5683 865 int32_t format_type=sdci[7]/10000;
5684 865 int32_t opacity=sdci[9]/10000;
5685 //sdci[8] not needed :)
5686
5687 //safe check
5688
1/2
✓ Branch 0 taken 865 times.
✗ Branch 1 not taken.
865 if(bg_color < -1) bg_color = -1;
5689
5690
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 if(opacity < 128)
5691 {
5692 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5693 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5694 clear_bitmap(pbmp);
5695 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
5696 if(format_type == 2) // right-sided text
5697 x-=width;
5698 else if(format_type == 1) // centered text
5699 x-=width/2;
5700 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5701 destroy_bitmap(pbmp);
5702 }
5703 else // no opacity
5704 {
5705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 if(format_type == 2) // right-sided text
5706 {
5707 textout_right_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5708 }
5709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865 times.
865 else if(format_type == 1) // centered text
5710 {
5711 textout_centre_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5712 }
5713 else // standard left-sided text
5714 {
5715 865 textout_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5716 }
5717 }
5718 865 }
5719
5720 45504 void bmp_do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5721 {
5722 //sdci[1]=layer
5723 //sdci[2]=x
5724 //sdci[3]=y
5725 //sdci[4]=font
5726 //sdci[5]=color
5727 //sdci[6]=bg color
5728 //sdci[7]=format_option
5729 //sdci[8]=string
5730 //sdci[9]=opacity
5731 //sdci[10]=shadowtype
5732 //sdci[11]=shadow_color
5733 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5735 {
5736 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5737 return;
5738 }
5739
5740 45504 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5741
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if ( refbmp == NULL ) return;
5742
5743
2/4
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45504 times.
45504 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5744
5745 45504 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5746
5747
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(!str)
5748 {
5749 al_trace("String pointer is null! Internal error. \n");
5750 return;
5751 }
5752
5753 45504 int32_t x=sdci[2]/10000;
5754 45504 int32_t y=sdci[3]/10000;
5755 45504 FONT* font=get_zc_font(sdci[4]/10000);
5756 45504 int32_t color=sdci[5]/10000;
5757 45504 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5758 45504 int32_t format_type=sdci[7]/10000;
5759 45504 int32_t opacity=sdci[9]/10000;
5760 45504 int32_t textstyle = sdci[10]/10000;
5761 45504 int32_t shadow_color = sdci[11]/10000;
5762 //sdci[8] not needed :)
5763
5764 //safe check
5765
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(bg_color < -1) bg_color = -1;
5766
5767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if(opacity < 128)
5768 {
5769 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5770 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5771 clear_bitmap(pbmp);
5772 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
5773 if(format_type == 2) // right-sided text
5774 x-=width;
5775 else if(format_type == 1) // centered text
5776 x-=width/2;
5777 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5778 destroy_bitmap(pbmp);
5779 }
5780 else // no opacity
5781 {
5782 45504 textout_styled_aligned_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
5783 }
5784 45504 }
5785
5786 325125 void bmp_do_clearr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5787 {
5788
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325125 times.
325125 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5789 {
5790 Z_scripterrlog("bitmap->Clear() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5791 return;
5792 }
5793
5794 325125 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 325125 times.
325125 if ( !refbmp ) return;
5796
5797 325125 clear_bitmap(refbmp);
5798 325125 }
5799
5800 3150 void bmp_do_clearcolorr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5801 {
5802 //sdci[1]=layer
5803 //sdci[2]=color
5804 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5805 3150 int32_t pal_color = sdci[2]/10000;
5806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3150 times.
3150 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5807 {
5808 Z_scripterrlog("bitmap->ClearToColor() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5809 return;
5810 }
5811
5812 3150 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3150 times.
3150 if ( !refbmp ) return;
5814
5815 3150 clear_to_color(refbmp, pal_color);
5816 3150 }
5817
5818
5819 34653 void bmp_do_regenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5820 {
5821 //sdci[1]=layer
5822 34653 int32_t h = sdci[3]/10000;
5823 34653 int32_t w = sdci[2]/10000;
5824
1/2
✓ Branch 0 taken 34653 times.
✗ Branch 1 not taken.
34653 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
5825 {
5826 //flip height and width
5827 h = h ^ w;
5828 w = h ^ w;
5829 h = h ^ w;
5830 }
5831 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5832 //Z_scripterrlog("bitmap->Create() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34653 times.
34653 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5834 {
5835 Z_scripterrlog("bitmap->Create() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5836 return;
5837 }
5838 34653 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5839 34653 auto& usr_bmp = scb.get(bitid);
5840
2/2
✓ Branch 0 taken 34528 times.
✓ Branch 1 taken 125 times.
34653 if ( usr_bmp.u_bmp )
5841 34528 destroy_bitmap(usr_bmp.u_bmp);
5842 34653 usr_bmp.u_bmp = create_bitmap_ex(8,w,h);
5843
5844 34653 usr_bmp.width = w;
5845 34653 usr_bmp.height = h;
5846 34653 }
5847
5848 void bmp_do_readr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5849 {
5850 //sdci[1]=layer
5851 //sdci[2]=filename
5852 //sdci[3]=y
5853 //sdci[4]=font
5854 //sdci[5]=color
5855 //sdci[6]=bg color
5856 //sdci[7]=format_option
5857 //sdci[8]=string
5858 //sdci[9]=opacity
5859 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5860 //Z_scripterrlog("bitmap->Read() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5861 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5862 {
5863 Z_scripterrlog("bitmap->Read() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5864 return;
5865 }
5866 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5867 auto& usr_bitmap = scb.get(bitid);
5868 usr_bitmap.destroy();
5869
5870 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5871
5872 if(!str)
5873 {
5874 al_trace("String pointer is null! Internal error. \n");
5875 return;
5876 }
5877
5878 PALETTE tempPal;
5879 get_palette(tempPal);
5880 if ( checkPath(str->c_str(), false) )
5881 {
5882 usr_bitmap.u_bmp = load_bitmap(str->c_str(), tempPal);
5883 usr_bitmap.width = usr_bitmap.u_bmp->w;
5884 usr_bitmap.height = usr_bitmap.u_bmp->h;
5885 if ( !usr_bitmap.u_bmp )
5886 {
5887 Z_scripterrlog("Failed to load image file %s.\nMaking a blank bitmap on the pointer.\n", str->c_str());
5888 }
5889 else
5890 {
5891 zprint("Read image file %s\n",str->c_str());
5892 }
5893 }
5894 else
5895 {
5896 Z_scripterrlog("Failed to load image file: %s. File not found. Creating a blank bitmap on the pointer.\n", str->c_str());
5897 usr_bitmap.u_bmp = create_bitmap_ex(8,256,176);
5898 clear_bitmap(usr_bitmap.u_bmp);
5899 }
5900 }
5901
5902
5903
5904 void bmp_do_writer(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5905 {
5906 //sdci[1]=layer
5907 //sdci[2]=filename
5908 //sdci[3]=y
5909 //sdci[4]=font
5910 //sdci[5]=color
5911 //sdci[6]=bg color
5912 //sdci[7]=format_option
5913 //sdci[8]=string
5914 //sdci[9]=opacity
5915 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5916 //Z_scripterrlog("bitmap->Write() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5917
5918 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5919 {
5920 Z_scripterrlog("bitmap->Write() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5921 return;
5922 }
5923
5924 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5925 if ( !refbmp ) return;
5926
5927 bool overwrite = (sdci[3] != 0);
5928 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5929
5930 if(!str)
5931 {
5932 al_trace("String pointer is null! Internal error. \n");
5933 return;
5934 }
5935
5936 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
5937 //std::strncpy(cptr, str->c_str(), str->size());
5938 //Z_scripterrlog("bitmap->Write extension matches ? : %s\n!", (FFCore.checkExtension(str->c_str(), ".png")) ? "true" : "false");
5939 //Z_scripterrlog("Trying to write filename %s\n", cptr);
5940 if
5941 (
5942 ( (FFCore.checkExtension(*str, "")) ) ||
5943 ( !(FFCore.checkExtension(*str, ".png")) && !(FFCore.checkExtension(*str, ".gif")) && !(FFCore.checkExtension(*str, ".bmp"))
5944 && !(FFCore.checkExtension(*str, ".pcx")) && !(FFCore.checkExtension(*str, ".tga")) )
5945 )
5946 {
5947 Z_scripterrlog("No extension, or invalid extension provided for writing bitmap file %s. Could not write the file.\nValid types are .png, .gif, .pcx, .tgx, and .bmp. Aborting.\n",str->c_str());
5948 }
5949 else if ( overwrite || (!checkPath(str->c_str(), false)) )
5950 {
5951 if(make_dirs_for_file(*str))
5952 {
5953 save_bitmap(str->c_str(), refbmp, RAMpal);
5954 if(checkPath(str->c_str(), false))
5955 {
5956 zprint("Wrote image file %s\n",str->c_str());
5957 }
5958 else
5959 {
5960 Z_scripterrlog("Failed to create file '%s'\n",str->c_str());
5961 }
5962 }
5963 else
5964 {
5965 Z_scripterrlog("Cannot write file '%s' because the directory does not exist, and could not be created.\n", str->c_str());
5966 }
5967 }
5968 else Z_scripterrlog("Cannot write file '%s' because the file already exists in the specified path.\n", str->c_str());
5969 }
5970
5971
5972 void bmp_do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5973 {
5974 //sdci[1]=layer
5975 //sdci[2]=x1
5976 //sdci[3]=y1
5977 //sdci[4]=x2
5978 //sdci[5]=y2
5979 //sdci[6]=x3
5980 //sdci[7]=y3
5981 //sdci[8]=x4
5982 //sdci[9]=y4
5983 //sdci[10]=width
5984 //sdci[11]=height
5985 //sdci[12]=cset
5986 //sdci[13]=flip
5987 //sdci[14]=tile/combo
5988 //sdci[15]=polytype
5989 //sdci[16] = other bitmap as texture
5990 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5991 Z_scripterrlog("bitmap quad pointer: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5992 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5993 {
5994 Z_scripterrlog("bitmap->Quad() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5995 return;
5996 }
5997 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
5998
5999 if ( !refbmp ) return;
6000
6001 int32_t x1 = sdci[2]/10000;
6002 int32_t y1 = sdci[3]/10000;
6003 int32_t x2 = sdci[4]/10000;
6004 int32_t y2 = sdci[5]/10000;
6005 int32_t x3 = sdci[6]/10000;
6006 int32_t y3 = sdci[7]/10000;
6007 int32_t x4 = sdci[8]/10000;
6008 int32_t y4 = sdci[9]/10000;
6009 int32_t w = sdci[10]/10000;
6010 int32_t h = sdci[11]/10000;
6011 int32_t color = sdci[12]/10000;
6012 int32_t flip=(sdci[13]/10000)&3;
6013 int32_t tile = sdci[14]/10000;
6014 int32_t polytype = sdci[15]/10000;
6015 int32_t quad_render_source = sdci[16];
6016 //Z_scripterrlog("bitmap->Quad() render source is: %d\n", quad_render_source);
6017
6018 bool tex_is_bitmap = ( sdci[16] != 0 );
6019
6020 BITMAP *bmptexture=NULL;
6021 BITMAP *tex=NULL;
6022 polytype = vbound(polytype, 0, 14);
6023
6024 int32_t col[4];
6025 col[0]=col[1]=col[2]=col[3]=color;
6026 bool mustDestroyBmp = false;
6027
6028 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6029
6030 if ( tex_is_bitmap )
6031 {
6032 bmptexture = resolveScriptingBitmap(quad_render_source);
6033 if ( !bmptexture )
6034 {
6035 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6036 tex_is_bitmap = 0;
6037 }
6038 }
6039
6040 if ( tex_is_bitmap )
6041 {
6042
6043 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6044 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
6045 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", w);
6046 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", h);
6047
6048 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6049 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6050 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6051 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6052
6053 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
6054 }
6055 else
6056 {
6057 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6058 if(!tex)
6059 {
6060 //Z_scripterrlog("Bitmap->Quad() found an invalid texture bitmap.\n");
6061 mustDestroyBmp = true;
6062 tex = create_bitmap_ex(8, w*16, h*16);
6063 clear_bitmap(tex);
6064 }
6065
6066 if(tile > 0) // TILE
6067 {
6068 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6069 }
6070
6071 if ( tile < 0 ) // COMBO
6072 {
6073 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
6074 const int32_t tiletodraw = combo_tile(c, x1, y1);
6075 flip = flip ^ c.flip;
6076
6077 if(!(c.animflags & AF_EDITOR_ONLY))
6078 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6079 }
6080 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6081 {
6082 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6083 return; //non power of two error
6084 }
6085 //Z_scripterrlog("bitmap->Quad() is trying to blit from a bitmap texture.\n");
6086 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6087 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6088 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6089 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6090
6091 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
6092
6093 }
6094
6095
6096
6097
6098 //todo: finish palette shading
6099 /*
6100 POLYTYPE_FLAT
6101 POLYTYPE_GCOL
6102 POLYTYPE_GRGB
6103 POLYTYPE_ATEX
6104 POLYTYPE_PTEX
6105 POLYTYPE_ATEX_MASK
6106 POLYTYPE_PTEX_MASK
6107 POLYTYPE_ATEX_LIT
6108 POLYTYPE_PTEX_LIT
6109 POLYTYPE_ATEX_MASK_LIT
6110 POLYTYPE_PTEX_MASK_LIT
6111 POLYTYPE_ATEX_TRANS
6112 POLYTYPE_PTEX_TRANS
6113 POLYTYPE_ATEX_MASK_TRANS
6114 POLYTYPE_PTEX_MASK_TRANS
6115 */
6116
6117 if(mustDestroyBmp)
6118 destroy_bitmap(tex);
6119
6120 }
6121
6122
6123 void bmp_do_getpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6124 {
6125 //sdci[1]=layer
6126 //sdci[2]=x1
6127 //sdci[3]=y1
6128
6129 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6130 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6131 {
6132 Z_scripterrlog("bitmap->GetPixel() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6133 return;
6134 }
6135 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
6136 if ( refbmp == NULL ) return;
6137
6138
6139 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6140
6141 int32_t x1 = sdci[2]/10000;
6142 int32_t y1 = (sdci[3]/10000)+yoffset;
6143 int32_t col = getpixel(refbmp, x1, y1);
6144 Z_scripterrlog("bitmap->GetPixel col is %d\n",col);
6145 Z_scripterrlog("bitmap->GetPixel bitmap ptr is is %d\n",(sdci[DRAWCMD_BMP_TARGET]));
6146 FFCore.set_sarg1(col);
6147 }
6148
6149
6150
6151
6152 void bmp_do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6153 {
6154 //sdci[1]=layer
6155 //sdci[2]=x1
6156 //sdci[3]=y1
6157 //sdci[4]=x2
6158 //sdci[5]=y2
6159 //sdci[6]=x3
6160 //sdci[7]=y3
6161 //sdci[8]=width
6162 //sdci[9]=height
6163 //sdci[10]=cset
6164 //sdci[11]=flip
6165 //sdci[12]=tile/combo
6166 //sdci[13]=polytype
6167 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6168 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6169 {
6170 Z_scripterrlog("bitmap->Triangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6171 return;
6172 }
6173 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
6174 if ( refbmp == NULL ) return;
6175
6176
6177 int32_t render_source = sdci[14];
6178 //Z_scripterrlog("bitmap->Triangle() render source is: %d\n", render_source);
6179
6180 bool tex_is_bitmap = ( sdci[14] != 0 );
6181
6182 BITMAP *bmptexture=NULL;
6183 if ( tex_is_bitmap )
6184 {
6185 bmptexture = resolveScriptingBitmap(render_source);
6186 if ( !bmptexture )
6187 {
6188 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6189 tex_is_bitmap = 0;
6190 }
6191 }
6192
6193 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6194
6195 int32_t x1 = sdci[2]/10000;
6196 int32_t y1 = sdci[3]/10000;
6197 int32_t x2 = sdci[4]/10000;
6198 int32_t y2 = sdci[5]/10000;
6199 int32_t x3 = sdci[6]/10000;
6200 int32_t y3 = sdci[7]/10000;
6201 int32_t w = sdci[8]/10000;
6202 int32_t h = sdci[9]/10000;
6203 int32_t color = sdci[10]/10000;
6204 int32_t flip=(sdci[11]/10000)&3;
6205 int32_t tile = sdci[12]/10000;
6206 int32_t polytype = sdci[13]/10000;
6207
6208 polytype = vbound(polytype, 0, 14);
6209 int32_t utex_w = w;
6210 int32_t utex_h = h;
6211
6212
6213 int32_t tex_width = w*16;
6214 int32_t tex_height = h*16;
6215
6216 bool mustDestroyBmp = false;
6217 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6218
6219 if(!tex)
6220 {
6221 mustDestroyBmp = true;
6222 tex = create_bitmap_ex(8, tex_width, tex_height);
6223 clear_bitmap(tex);
6224 }
6225
6226 int32_t col[3];
6227 /*
6228 if( color < 0 )
6229 {
6230 col[0]=draw_container.color_buffer[0];
6231 col[1]=draw_container.color_buffer[1];
6232 col[2]=draw_container.color_buffer[2];
6233 }
6234 else */
6235 {
6236 col[0]=col[1]=col[2]=color;
6237 }
6238
6239 if(tile > 0) // TILE
6240 {
6241 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6242 }
6243 else // COMBO
6244 {
6245 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
6246 const int32_t tiletodraw = combo_tile(c, x1, y1);
6247 flip = flip ^ c.flip;
6248
6249 if(!(c.animflags & AF_EDITOR_ONLY))
6250 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6251 }
6252 if ( !tex_is_bitmap )
6253 {
6254 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6255 {
6256 Z_message("bitmap->Triangle() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6257 return; //non power of two error
6258 }
6259 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6260 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
6261 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
6262
6263
6264 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
6265
6266 }
6267
6268 else
6269 {
6270 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6271 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6272 if ( !isPowerOfTwo(utex_h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_w);
6273 if ( !isPowerOfTwo(utex_w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_h);
6274
6275 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6276 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(utex_h), col[1] };
6277 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(utex_w), static_cast<float>(utex_h), col[2] };
6278
6279
6280 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
6281
6282 }
6283
6284 if(mustDestroyBmp)
6285 destroy_bitmap(tex);
6286 }
6287
6288
6289 void bmp_do_mode7r(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6290 {
6291 /*
6292 int32_t layer, int32_t rt, int32_t srcX, int32_t srcY, int32_t srcW, int32_t srcH, int32_t destW, int32_t destH, int32_t angle, int32_t cx, int32_t cy, int32_t space_z, int32_t horizon,
6293 int32_t scale_x, int32_t scale_y){
6294
6295 //sdci[1]=layer
6296 //sdci[2]=bitmap target
6297 //
6298 // -2 is the current Render Target
6299 // -1, this is the screen (framebuf).
6300 // 0: Render target 0
6301 // 1: Render target 1
6302 // 2: Render target 2
6303 // 3: Render target 3
6304 // 4: Render target 4
6305 // 5: Render target 5
6306 // 6: Render target 6
6307 // Otherwise: The pointer to a bitmap.
6308
6309 //sdci[3]=sourcex
6310 //sdci[4]=sourcey
6311 //sdci[5]=sourcew
6312 //sdci[6]=sourceh
6313
6314 //sdci[7]=destw
6315 //sdci[8]=desth
6316 //sdci[9]=angle
6317 //scdi[10] = pivot cx
6318 //sdci[11] = pivot cy
6319 //sdci[12] = space Z
6320 //sdci[13] = horizon
6321 //scdi[14] = scale X
6322 //scdi[15] = scale Y
6323 //sdci[16] = masked?
6324 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6325
6326
6327
6328 // ZScript-side constant values:
6329 const int32_t BITDX_NORMAL = 0;
6330 const int32_t BITDX_TRANS = 1; //Translucent
6331 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6332 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6333 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6334 //Note: Some modes cannot be combined. if a combination is not supported, an error
6335 // detailing this will be shown in allegro.log.
6336
6337 //scdi[15] = litcolour
6338 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6339 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6340
6341 //sdci[16]=mask
6342
6343 */
6344
6345
6346 int32_t bitmapIndex = sdci[2];
6347 int32_t usr_bitmap_index = sdci[2];
6348 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6349 //Z_scripterrlog("DrawPlane() bitmapIndex is: %d\n", bitmapIndex);
6350
6351 if ( bitmapIndex >= 10000 )
6352 {
6353 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6354 }
6355 else if ( usr_bitmap_index > 0 )
6356 {
6357 bitmapIndex = usr_bitmap_index;
6358 // Z_scripterrlog("Mode7 is using a user bitmap target, pointer: %d\n", usr_bitmap_index);
6359 yoffset = 0;
6360 }
6361
6362 //rendering mode 7 args
6363 double srcX = sdci[3]/10000.0;
6364 double srcY = sdci[4]/10000.0;
6365 double destX = sdci[5]/10000.0;
6366 double destY = sdci[6]/10000.0;
6367
6368 double destW = sdci[7]/10000.0;
6369 double destH = sdci[8]/10000.0;
6370 double space_z = sdci[9]/10000.0;
6371 double horizon = sdci[10]/10000.0;
6372 double scale_x = sdci[11]/10000.0;
6373 double scale_y = sdci[12]/10000.0;
6374 byte masked = ( sdci[13] ) ? 1 : 0;
6375
6376
6377 int32_t ref = 0;
6378
6379 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6380 //Do we need to also check the render target and do the same thing if the
6381 //dest == -2 and the render target is not RT_SCREEN?
6382
6383 ref = sdci[DRAWCMD_BMP_TARGET];
6384
6385
6386 if ( ref <= 0 )
6387 {
6388 Z_scripterrlog("bitmap->DrawPlane() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6389 return;
6390 }
6391 BITMAP *sourceBitmap = resolveScriptingBitmap(ref); //This can be the screen, as -1.
6392
6393 if(!sourceBitmap)
6394 {
6395 Z_message("Warning: %d->DrawPlane() source bitmap contains invalid data or is not initialized.\n", ref);
6396 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6397 return;
6398 }
6399
6400 BITMAP *destBMP=NULL;
6401 switch(bitmapIndex)
6402 {
6403 // Current render target (RT_CURRENT).
6404 // This is the only reason we aren't using resolveScriptingBitmap for the target bitmap. All the other cases should be equivalent.
6405 case -2:
6406 {
6407 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6408 if ( curr_rt >= 0 && curr_rt < 7 )
6409 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6410 else destBMP = bmp; //screen
6411 break;
6412 }
6413 case -1:
6414 destBMP = bmp; //this is framebuf, by default
6415 break;
6416
6417 //1 through 6 are the old system bitmaps (Render Targets)
6418 case 0:
6419 case 1:
6420 case 2:
6421 case 3:
6422 case 4:
6423 case 5:
6424 case 6:
6425 {
6426 //This gets a render target.
6427 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6428 break;
6429 }
6430 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6431 default:
6432 {
6433 auto& usr_bitmap = scb.get(usr_bitmap_index);
6434 destBMP = usr_bitmap.u_bmp;
6435 if ( !usr_bitmap.u_bmp )
6436 {
6437 Z_scripterrlog("Target for bitmap->DrawPlane is uninitialised. Aborting.\n");
6438 break;
6439 }
6440 }
6441 }
6442
6443 if (!destBMP)
6444 {
6445 Z_message("Warning: DrawPlane(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6446 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6447 return;
6448 }
6449
6450 //dx = dx + xoffset; //don't do this here!
6451 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6452 //All of these are a factor of 10000 as fix.
6453 int32_t screen_x = 0; int32_t screen_y = 0;
6454
6455 double distance = 0; double horizontal_scale = 0;
6456
6457 int32_t screen_y_horizon = 0;
6458
6459 double line_dx = 0; double line_dy = 0;
6460
6461 int32_t space_x = 0; int32_t space_y = 0;
6462
6463 for(screen_y = 0; screen_y < destH; screen_y++) //fix, offset by .0000
6464 {
6465 //Calculate the distance of each line from the camera point
6466 screen_y_horizon = screen_y + horizon;
6467
6468 distance = ((space_z * scale_y) / ((screen_y_horizon != 0) ? screen_y_horizon : 1));
6469
6470 //Get the scale of each line based on the distance
6471
6472 horizontal_scale = (distance / (( scale_x != 0 ) ? scale_x : 1));
6473
6474 //There was some math here before I stripped out the rotation step
6475 line_dx = horizontal_scale;
6476 line_dy = 0;
6477
6478 //space_x,space_y - where to grab each scanline from on the space bitmap
6479 space_x = srcX - destW/2.0 * line_dx;
6480 space_y = srcY - distance + destH/2.0 * line_dy;
6481
6482 //Keep blits within the bounds of both bitmaps to avoid crashes
6483 int32_t y1 = srcY+space_y;
6484 int32_t y2 = destY+screen_y;
6485 if(y1 >=0 && y1 <= (sourceBitmap->h-1) && y2 >=0 && y2 <= (destBMP->h-1) )
6486 {
6487 if ( masked ) masked_stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6488 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6489 else stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6490 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6491 }
6492 }
6493 }
6494
6495
6496 //Draw]()
6497 265749 void bmp_do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6498 {
6499 /*
6500 //sdci[1]=layer
6501 //sdci[2]=bitmap target
6502 //
6503 // -2 is the current Render Target
6504 // -1, this is the screen (framebuf).
6505 // 0: Render target 0
6506 // 1: Render target 1
6507 // 2: Render target 2
6508 // 3: Render target 3
6509 // 4: Render target 4
6510 // 5: Render target 5
6511 // 6: Render target 6
6512 // Otherwise: The pointer to a bitmap.
6513
6514 //sdci[3]=sourcex
6515 //sdci[4]=sourcey
6516 //sdci[5]=sourcew
6517 //sdci[6]=sourceh
6518 //sdci[7]=destx
6519 //sdci[8]=desty
6520 //sdci[9]=destw
6521 //sdci[10]=desth
6522 //sdci[11]=rotation/angle
6523 //scdi[12] = pivot cx
6524 //sdci[13] = pivot cy
6525 //scdi[14] = effect flags
6526 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6527
6528 // ZScript-side constant values:
6529 const int32_t BITDX_NORMAL = 0;
6530 const int32_t BITDX_TRANS = 1; //Translucent
6531 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6532 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6533 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6534 //Note: Some modes cannot be combined. if a combination is not supported, an error
6535 // detailing this will be shown in allegro.log.
6536
6537 //scdi[15] = litcolour
6538 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6539 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6540
6541 //sdci[16]=mask
6542
6543 */
6544
6545 265749 int32_t usr_bitmap_index = sdci[2];
6546 531498 auto [bitmapIndex, is_user_bitmap] = resolveScriptingBitmapId(usr_bitmap_index);
6547
6548
6549 265749 int32_t sx = sdci[3]/10000;
6550 265749 int32_t sy = sdci[4]/10000;
6551 265749 int32_t sw = sdci[5]/10000;
6552 265749 int32_t sh = sdci[6]/10000;
6553 265749 int32_t dx = sdci[7]/10000;
6554 265749 int32_t dy = sdci[8]/10000;
6555 265749 int32_t dw = sdci[9]/10000;
6556 265749 int32_t dh = sdci[10]/10000;
6557 265749 float rot = sdci[11]/10000;
6558 265749 int32_t cx = sdci[12]/10000;
6559 265749 int32_t cy = sdci[13]/10000;
6560 265749 int32_t mode = sdci[14]/10000;
6561 265749 int32_t litcolour = sdci[15]/10000;
6562 265749 bool masked = (sdci[16] != 0);
6563
6564 265749 int32_t ref = 0;
6565
6566
2/2
✓ Branch 0 taken 265389 times.
✓ Branch 1 taken 360 times.
265749 if (get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
6567 {
6568
2/2
✓ Branch 0 taken 93046 times.
✓ Branch 1 taken 172343 times.
265389 if (is_user_bitmap)
6569 172343 yoffset = 0;
6570
6571 265389 dx += xoffset;
6572 265389 dy += yoffset;
6573 265389 }
6574 else
6575 {
6576 360 dx += secondary_draw_origin_xoff;
6577 360 dy += secondary_draw_origin_yoff;
6578
6579 360 sx += xoffset;
6580 360 sy += yoffset;
6581 }
6582
6583 265749 ref = sdci[DRAWCMD_BMP_TARGET];
6584
6585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 265749 times.
265749 if ( ref <= 0 )
6586 {
6587 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6588 return;
6589 }
6590 265749 BITMAP *sourceBitmap = resolveScriptingBitmap(ref); //This can be the screen, as -1.
6591
6592
1/2
✓ Branch 0 taken 265749 times.
✗ Branch 1 not taken.
265749 if(!sourceBitmap)
6593 {
6594
6595 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
6596 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6597 return;
6598 }
6599
6600 265749 BITMAP *destBMP=NULL;
6601
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 172343 times.
✓ Branch 2 taken 786 times.
✓ Branch 3 taken 92620 times.
265749 switch(bitmapIndex)
6602 {
6603 // Current render target (RT_CURRENT).
6604 // This is the only reason we aren't using resolveScriptingBitmap for the target bitmap. All the other cases should be equivalent.
6605 case -2:
6606 {
6607 786 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6608
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
786 if ( curr_rt >= 0 && curr_rt < 7 )
6609 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6610 786 else destBMP = bmp; //screen
6611 786 break;
6612 }
6613 case -1:
6614 92620 destBMP = bmp; //this is framebuf, by default
6615 92620 break;
6616 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6617 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6618 //destBMP = framebuf; //Drawing to the screen.
6619 //break;
6620
6621 //1 through 6 are the old system bitmaps (Render Targets)
6622 case 0:
6623 case 1:
6624 case 2:
6625 case 3:
6626 case 4:
6627 case 5:
6628 case 6:
6629 {
6630 //This gets a render target.
6631 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6632
6633 //destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6634 //sdci[18] = bitmapIndex;
6635 break;
6636 }
6637 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6638 default:
6639 {
6640 172343 auto& usr_bitmap = scb.get(usr_bitmap_index);
6641 172343 destBMP = usr_bitmap.u_bmp;
6642 //sdci[18] = usr_bitmap_index;
6643
1/2
✓ Branch 0 taken 172343 times.
✗ Branch 1 not taken.
172343 if ( !usr_bitmap.u_bmp )
6644 {
6645 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
6646 break;
6647 }
6648 }
6649 172343 }
6650
6651
1/2
✓ Branch 0 taken 265749 times.
✗ Branch 1 not taken.
265749 if (!destBMP)
6652 {
6653 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6654 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6655 return;
6656 }
6657
6658
2/2
✓ Branch 0 taken 1027 times.
✓ Branch 1 taken 264722 times.
265749 bool stretched = (sw != dw || sh != dh);
6659 265749 BITMAP* subBmp = 0;
6660
6661
4/4
✓ Branch 0 taken 264170 times.
✓ Branch 1 taken 1579 times.
✓ Branch 2 taken 24983 times.
✓ Branch 3 taken 239187 times.
265749 if(rot != 0 || mode != 0)
6662 {
6663 26562 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
6664 26562 clear_bitmap(subBmp);
6665
6666
1/2
✓ Branch 0 taken 26562 times.
✗ Branch 1 not taken.
26562 if(!subBmp)
6667 {
6668
6669 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
6670 return;
6671 }
6672 26562 }
6673 265749 BITMAP* sbmp = sourceBitmap;
6674
2/4
✓ Branch 0 taken 265749 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 265749 times.
265749 if (sx + sw > sbmp->w || sy + sh > sbmp->h)
6675 {
6676 sbmp = create_bitmap_ex(8, sw, sh);
6677 clear_bitmap(sbmp);
6678 blit(sourceBitmap, sbmp, sx, sy, 0, 0, std::min(sourceBitmap->w-sx, sw), std::min(sourceBitmap->h-sy, sh));
6679 sx = 0;
6680 sy = 0;
6681 }
6682 //dx = dx + xoffset; //don't do this here!
6683 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6684
6685
2/2
✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 264147 times.
265749 if(stretched)
6686 {
6687
2/2
✓ Branch 0 taken 1475 times.
✓ Branch 1 taken 127 times.
1602 if(masked)
6688 { //stretched and masked
6689
2/2
✓ Branch 0 taken 574 times.
✓ Branch 1 taken 901 times.
1475 if ( rot == 0 )
6690 { //if not rotated
6691
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
901 switch(mode)
6692 {
6693 case 1:
6694 //transparent
6695 900 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6696 900 draw_trans_sprite(destBMP, subBmp, dx, dy);
6697 900 break;
6698
6699
6700 case 2:
6701 //pivot?
6702 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6703 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6704 //Pivoting requires two more args
6705 break;
6706
6707 case 3:
6708 //pivot + trans
6709 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6710 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6711 break;
6712
6713 case 4:
6714 //flip v
6715 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6716 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6717 break;
6718
6719 case 5:
6720 //trans + v flip
6721 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6722 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6723 break;
6724
6725 case 6:
6726 //pivot + v flip
6727 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6728 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6729 break;
6730
6731 case 8:
6732 //vlip h
6733 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6734 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6735 break;
6736
6737 case 9:
6738 //trans + h flip
6739 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6740 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6741 break;
6742
6743 case 10:
6744 //flip H and pivot
6745 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6746 //return error cannot pivot and h flip
6747 break;
6748
6749 case 12:
6750 //vh flip
6751 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6752 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6753 break;
6754
6755 case 13:
6756 //trans + vh flip
6757 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6758 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6759 break;
6760
6761 case 14:
6762 //pivot and vh flip
6763 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6764 //return error cannot both pivot and vh flip
6765 break;
6766
6767 case 16:
6768 //lit
6769 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6770 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6771 break;
6772
6773 case 18:
6774 //pivot, lit
6775 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6776 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6777 break;
6778
6779 case 20:
6780 //lit + v flip
6781 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6782 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6783 break;
6784
6785 case 22:
6786 //Pivot, vflip, lit
6787 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6788 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6789 break;
6790
6791 case 24:
6792 //lit + h flip
6793 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6794 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6795 break;
6796
6797 case 26:
6798 //pivot + lit + hflip
6799 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
6800 //return error cannot pivot, lit, and flip
6801 break;
6802
6803 case 28:
6804 //lit + vh flip
6805 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6806 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
6807 break;
6808
6809 case 32: //gouraud
6810 //Probably not wort supporting.
6811 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6812 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6813 break;
6814
6815 case 0:
6816 //no effect
6817 1 masked_stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
6818 1 break;
6819
6820
6821 default:
6822
6823 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6824
6825
6826 }
6827 901 } //end if not rotated
6828
6829
2/2
✓ Branch 0 taken 901 times.
✓ Branch 1 taken 574 times.
1475 if ( rot != 0 ) //if rotated
6830 {
6831
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 574 times.
✗ Branch 21 not taken.
574 switch(mode)
6832 {
6833 case 1:
6834 //transparent
6835 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6836 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6837
6838 break;
6839
6840 case 2:
6841 //pivot?
6842 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6843 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6844 //Pivoting requires two more args
6845 break;
6846
6847 case 3:
6848 //pivot + trans
6849 //return an error, cannot both rotate and pivot
6850 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6851 break;
6852
6853 case 4:
6854 //flip v
6855 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6856 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6857 break;
6858
6859 case 5:
6860 //trans + v flip
6861 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6862 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6863 break;
6864
6865 case 6:
6866 //pivot + v flip
6867 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6868 //return an error, cannot both rotate and pivot
6869 break;
6870
6871 case 8:
6872 //flip h
6873 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
6874 //return an error, cannot both rotate and flip H
6875 break;
6876
6877 case 9:
6878 //trans + h flip
6879 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
6880 //return an error, cannot rotate and flip a trans sprite
6881 break;
6882
6883 case 10:
6884 //flip H and pivot
6885 //return error cannot pivot and h flip
6886 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6887 break;
6888
6889 case 12:
6890 //vh flip
6891 //return an error, cannot rotate and VH flip a trans sprite
6892 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6893 break;
6894
6895 case 13:
6896 //trans + vh flip
6897 //return an error, cannot rotate and VH flip a trans sprite
6898 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6899 break;
6900
6901 case 14:
6902 //pivot and vh flip
6903 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6904 //return error cannot both pivot and vh flip
6905 break;
6906
6907 case 16:
6908 //lit
6909 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6910 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6911 break;
6912
6913 case 18:
6914 //pivot, lit
6915 //return an error, cannot both rotate and pivot
6916 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6917 break;
6918
6919 case 20:
6920 //lit + vflip
6921 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6922 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6923 break;
6924
6925 case 22:
6926 //Pivot, vflip, lit
6927 //return an error, cannot both rotate and pivot
6928 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6929 break;
6930
6931 case 24:
6932 //lit + h flip
6933 //return an error, cannot both rotate and H flip
6934 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
6935 break;
6936
6937 case 26:
6938 //pivot + lit + hflip
6939 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
6940 //return error cannot pivot, lit, and flip
6941 break;
6942
6943 case 28:
6944 //lit + vh flip
6945 //return an error, cannot both rotate and VH flip
6946 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6947 break;
6948
6949 case 32: //gouraud
6950 //Probably not wort supporting.
6951 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6952 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6953 break;
6954
6955 case 0:
6956 //no effect.
6957 574 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6958 574 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6959 574 break;
6960
6961 default:
6962
6963 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6964
6965 }
6966 574 }
6967 1475 } //end if stretched and masked
6968
6969 else //stretched, not masked
6970 {
6971
6972
6973
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( rot == 0 ) //if not rotated
6974 {
6975
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 127 times.
127 switch(mode)
6976 {
6977 case 1:
6978 //transparent
6979 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6980 draw_trans_sprite(destBMP, subBmp, dx, dy);
6981 break;
6982
6983
6984 case 2:
6985 //pivot?
6986 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6987 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6988 //Pivoting requires two more args
6989 break;
6990
6991 case 3:
6992 //pivot + trans
6993 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6994 pivot_sprite_trans(destBMP, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
6995 break;
6996
6997 case 4:
6998 //flip v
6999 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7000 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7001 break;
7002
7003 case 5:
7004 //trans + v flip
7005 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7006 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7007 break;
7008
7009 case 6:
7010 //pivot + v flip
7011 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7012 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7013 break;
7014
7015 case 8:
7016 //vlip h
7017 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7018 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7019 break;
7020
7021 case 9:
7022 //trans + h flip
7023 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7024 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7025 break;
7026
7027 case 10:
7028 //flip H and pivot
7029 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7030 //return error cannot pivot and h flip
7031 break;
7032
7033 case 12:
7034 //vh flip
7035 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7036 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7037 break;
7038
7039 case 13:
7040 //trans + vh flip
7041 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7042 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7043 break;
7044
7045 case 14:
7046 //pivot and vh flip
7047 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7048 //return error cannot both pivot and vh flip
7049 break;
7050
7051 case 16:
7052 //lit
7053 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7054 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7055 break;
7056
7057 case 18:
7058 //pivot, lit
7059 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7060 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7061 break;
7062
7063 case 20:
7064 //lit + v flip
7065 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7066 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7067 break;
7068
7069 case 22:
7070 //Pivot, vflip, lit
7071 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7072 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7073 break;
7074
7075 case 24:
7076 //lit + h flip
7077 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7078 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7079 break;
7080
7081 case 26:
7082 //pivot + lit + hflip
7083 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7084 //return error cannot pivot, lit, and flip
7085 break;
7086
7087 case 28:
7088 //lit + vh flip
7089 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7090 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7091 break;
7092
7093 case 32: //gouraud
7094 //Probably not wort supporting.
7095 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7096 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7097 break;
7098
7099 case 0:
7100 //no effect
7101 127 stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
7102 127 break;
7103
7104
7105 default:
7106
7107 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7108
7109
7110 }
7111 127 } //end if not rotated
7112
7113
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if ( rot != 0 ) //if rotated
7114 {
7115 switch(mode)
7116 {
7117 case 1:
7118 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7119 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7120
7121 break;
7122
7123 case 2:
7124 //pivot?
7125 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7126 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7127 //Pivoting requires two more args
7128 break;
7129
7130 case 3:
7131 //pivot + trans
7132 //return an error, cannot both rotate and pivot
7133 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7134 break;
7135
7136 case 4:
7137 //flip v
7138 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7139 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7140 break;
7141
7142 case 5:
7143 //trans + v flip
7144 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7145 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7146 break;
7147
7148 case 6:
7149 //pivot + v flip
7150 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7151 //return an error, cannot both rotate and pivot
7152 break;
7153
7154 case 8:
7155 //flip h
7156 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7157 //return an error, cannot both rotate and flip H
7158 break;
7159
7160 case 9:
7161 //trans + h flip
7162 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7163 //return an error, cannot rotate and flip a trans sprite
7164 break;
7165
7166 case 10:
7167 //flip H and pivot
7168 //return error cannot pivot and h flip
7169 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7170 break;
7171
7172 case 12:
7173 //vh flip
7174 //return an error, cannot rotate and VH flip a trans sprite
7175 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7176 break;
7177
7178 case 13:
7179 //trans + vh flip
7180 //return an error, cannot rotate and VH flip a trans sprite
7181 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7182 break;
7183
7184 case 14:
7185 //pivot and vh flip
7186 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7187 //return error cannot both pivot and vh flip
7188 break;
7189
7190 case 16:
7191 //lit
7192 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7193 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7194 break;
7195
7196 case 18:
7197 //pivot, lit
7198 //return an error, cannot both rotate and pivot
7199 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7200 break;
7201
7202 case 20:
7203 //lit + vflip
7204 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7205 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7206 break;
7207
7208 case 22:
7209 //Pivot, vflip, lit
7210 //return an error, cannot both rotate and pivot
7211 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7212 break;
7213
7214 case 24:
7215 //lit + h flip
7216 //return an error, cannot both rotate and H flip
7217 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7218 break;
7219
7220 case 26:
7221 //pivot + lit + hflip
7222 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7223 //return error cannot pivot, lit, and flip
7224 break;
7225
7226 case 28:
7227 //lit + vh flip
7228 //return an error, cannot both rotate and VH flip
7229 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7230 break;
7231
7232 case 32: //gouraud
7233 //Probably not wort supporting.
7234 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7235 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7236 break;
7237
7238 case 0:
7239 //no effect.
7240 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7241 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7242 break;
7243
7244 default:
7245
7246 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7247
7248 }
7249 }
7250
7251 } //end if stretched, but not masked
7252 1602 }
7253 else //not stretched
7254 {
7255
7256
2/2
✓ Branch 0 taken 253164 times.
✓ Branch 1 taken 10983 times.
264147 if(masked) //if masked, but not stretched
7257 {
7258
7259
2/2
✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 252159 times.
253164 if ( rot == 0 ) //if not rotated
7260 {
7261
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 18689 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 233470 times.
252159 switch(mode)
7262 {
7263 case 1:
7264 //transparent
7265 18689 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7266 18689 draw_trans_sprite(destBMP, subBmp, dx, dy);
7267 18689 break;
7268
7269
7270 case 2:
7271 //pivot?
7272 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7273 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7274 //Pivoting requires two more args
7275 break;
7276
7277 case 3:
7278 //pivot + trans
7279 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7280 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7281 break;
7282
7283 case 4:
7284 //flip v
7285 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7286 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7287 break;
7288
7289 case 5:
7290 //trans + v flip
7291 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7292 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7293 break;
7294
7295 case 6:
7296 //pivot + v flip
7297 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7298 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7299 break;
7300
7301 case 8:
7302 //vlip h
7303 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7304 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7305 break;
7306
7307 case 9:
7308 //trans + h flip
7309 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7310 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7311 break;
7312
7313 case 10:
7314 //flip H and pivot
7315 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7316 //return error cannot pivot and h flip
7317 break;
7318
7319 case 12:
7320 //vh flip
7321 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7322 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7323 break;
7324
7325 case 13:
7326 //trans + vh flip
7327 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7328 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7329 break;
7330
7331 case 14:
7332 //pivot and vh flip
7333 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7334 //return error cannot both pivot and vh flip
7335 break;
7336
7337 case 16:
7338 //lit
7339 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7340 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7341 break;
7342
7343 case 18:
7344 //pivot, lit
7345 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7346 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7347 break;
7348
7349 case 20:
7350 //lit + v flip
7351 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7352 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7353 break;
7354
7355 case 22:
7356 //Pivot, vflip, lit
7357 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7358 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7359 break;
7360
7361 case 24:
7362 //lit + h flip
7363 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7364 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7365 break;
7366
7367 case 26:
7368 //pivot + lit + hflip
7369 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7370 //return error cannot pivot, lit, and flip
7371 break;
7372
7373 case 28:
7374 //lit + vh flip
7375 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7376 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7377 break;
7378
7379 case 32: //gouraud
7380 //Probably not wort supporting.
7381 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7382 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7383 break;
7384
7385 case 0:
7386 //no effect
7387 233470 masked_blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7388 233470 break;
7389
7390
7391 default:
7392
7393 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7394
7395
7396 }
7397 252159 } //end if not rotated
7398
7399
2/2
✓ Branch 0 taken 252159 times.
✓ Branch 1 taken 1005 times.
253164 if ( rot != 0 ) //if rotated
7400 {
7401
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 1005 times.
✗ Branch 21 not taken.
1005 switch(mode)
7402 {
7403 case 1:
7404 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
7405 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7406
7407 break;
7408
7409 case 2:
7410 //pivot?
7411 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7412 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7413 //Pivoting requires two more args
7414 break;
7415
7416 case 3:
7417 //pivot + trans
7418 //return an error, cannot both rotate and pivot
7419 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7420 break;
7421
7422 case 4:
7423 //flip v
7424 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7425 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7426 break;
7427
7428 case 5:
7429 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
7430 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7431 break;
7432
7433 case 6:
7434 //pivot + v flip
7435 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7436 //return an error, cannot both rotate and pivot
7437 break;
7438
7439 case 8:
7440 //flip h
7441 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7442 //return an error, cannot both rotate and flip H
7443 break;
7444
7445 case 9:
7446 //trans + h flip
7447 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7448 //return an error, cannot rotate and flip a trans sprite
7449 break;
7450
7451 case 10:
7452 //flip H and pivot
7453 //return error cannot pivot and h flip
7454 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7455 break;
7456
7457 case 12:
7458 //vh flip
7459 //return an error, cannot rotate and VH flip a trans sprite
7460 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7461 break;
7462
7463 case 13:
7464 //trans + vh flip
7465 //return an error, cannot rotate and VH flip a trans sprite
7466 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7467 break;
7468
7469 case 14:
7470 //pivot and vh flip
7471 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7472 //return error cannot both pivot and vh flip
7473 break;
7474
7475 case 16:
7476 //lit
7477 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7478 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7479 break;
7480
7481 case 18:
7482 //pivot, lit
7483 //return an error, cannot both rotate and pivot
7484 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7485 break;
7486
7487 case 20:
7488 //lit + vflip
7489 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7490 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7491 break;
7492
7493 case 22:
7494 //Pivot, vflip, lit
7495 //return an error, cannot both rotate and pivot
7496 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7497 break;
7498
7499 case 24:
7500 //lit + h flip
7501 //return an error, cannot both rotate and H flip
7502 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7503 break;
7504
7505 case 26:
7506 //pivot + lit + hflip
7507 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7508 //return error cannot pivot, lit, and flip
7509 break;
7510
7511 case 28:
7512 //lit + vh flip
7513 //return an error, cannot both rotate and VH flip
7514 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7515 break;
7516
7517 case 32: //gouraud
7518 //Probably not wort supporting.
7519 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7520 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7521 break;
7522
7523 case 0:
7524 //no effect.
7525 1005 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7526 1005 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7527 1005 break;
7528
7529 default:
7530
7531 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7532
7533 }
7534 1005 } //end rtated, masked
7535 253164 } //end if masked
7536
7537 else //not masked, and not stretched; just blit
7538 {
7539
7540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10983 times.
10983 if ( rot == 0 ) //if not rotated
7541 {
7542
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 5394 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5589 times.
10983 switch(mode)
7543 {
7544 case 1:
7545 //transparent
7546 5394 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7547 5394 draw_trans_sprite(destBMP, subBmp, dx, dy);
7548 5394 break;
7549
7550
7551 case 2:
7552 //pivot?
7553 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7554 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7555 //Pivoting requires two more args
7556 break;
7557
7558 case 3:
7559 //pivot + trans
7560 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7561 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7562 break;
7563
7564 case 4:
7565 //flip v
7566 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7567 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7568 break;
7569
7570 case 5:
7571 //trans + v flip
7572 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7573 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7574 break;
7575
7576 case 6:
7577 //pivot + v flip
7578 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7579 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7580 break;
7581
7582 case 8:
7583 //vlip h
7584 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7585 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7586 break;
7587
7588 case 9:
7589 //trans + h flip
7590 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7591 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7592 break;
7593
7594 case 10:
7595 //flip H and pivot
7596 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7597 //return error cannot pivot and h flip
7598 break;
7599
7600 case 12:
7601 //vh flip
7602 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7603 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7604 break;
7605
7606 case 13:
7607 //trans + vh flip
7608 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7609 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7610 break;
7611
7612 case 14:
7613 //pivot and vh flip
7614 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7615 //return error cannot both pivot and vh flip
7616 break;
7617
7618 case 16:
7619 //lit
7620 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7621 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7622 break;
7623
7624 case 18:
7625 //pivot, lit
7626 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7627 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7628 break;
7629
7630 case 20:
7631 //lit + v flip
7632 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7633 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7634 break;
7635
7636 case 22:
7637 //Pivot, vflip, lit
7638 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7639 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7640 break;
7641
7642 case 24:
7643 //lit + h flip
7644 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7645 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7646 break;
7647
7648 case 26:
7649 //pivot + lit + hflip
7650 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7651 //return error cannot pivot, lit, and flip
7652 break;
7653
7654 case 28:
7655 //lit + vh flip
7656 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7657 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7658 break;
7659
7660 case 32: //gouraud
7661 //Probably not wort supporting.
7662 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7663 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7664 break;
7665
7666 case 0:
7667 //no effect
7668 5589 blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7669 5589 break;
7670
7671
7672 default:
7673
7674 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7675
7676
7677 }
7678 10983 } //end if not rotated
7679
7680
1/2
✓ Branch 0 taken 10983 times.
✗ Branch 1 not taken.
10983 if ( rot != 0 ) //if rotated
7681 {
7682 switch(mode)
7683 {
7684 case 1:
7685 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
7686 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7687
7688 break;
7689
7690 case 2:
7691 //pivot?
7692 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7693 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7694 //Pivoting requires two more args
7695 break;
7696
7697 case 3:
7698 //pivot + trans
7699 //return an error, cannot both rotate and pivot
7700 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7701 break;
7702
7703 case 4:
7704 //flip v
7705 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7706 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7707 break;
7708
7709 case 5:
7710 //trans + v flip
7711 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7712 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7713 break;
7714
7715 case 6:
7716 //pivot + v flip
7717 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7718 //return an error, cannot both rotate and pivot
7719 break;
7720
7721 case 8:
7722 //flip h
7723 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7724 //return an error, cannot both rotate and flip H
7725 break;
7726
7727 case 9:
7728 //trans + h flip
7729 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7730 //return an error, cannot rotate and flip a trans sprite
7731 break;
7732
7733 case 10:
7734 //flip H and pivot
7735 //return error cannot pivot and h flip
7736 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7737 break;
7738
7739 case 12:
7740 //vh flip
7741 //return an error, cannot rotate and VH flip a trans sprite
7742 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7743 break;
7744
7745 case 13:
7746 //trans + vh flip
7747 //return an error, cannot rotate and VH flip a trans sprite
7748 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7749 break;
7750
7751 case 14:
7752 //pivot and vh flip
7753 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7754 //return error cannot both pivot and vh flip
7755 break;
7756
7757 case 16:
7758 //lit
7759 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7760 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7761 break;
7762
7763 case 18:
7764 //pivot, lit
7765 //return an error, cannot both rotate and pivot
7766 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7767 break;
7768
7769 case 20:
7770 //lit + vflip
7771 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7772 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7773 break;
7774
7775 case 22:
7776 //Pivot, vflip, lit
7777 //return an error, cannot both rotate and pivot
7778 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7779 break;
7780
7781 case 24:
7782 //lit + h flip
7783 //return an error, cannot both rotate and H flip
7784 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7785 break;
7786
7787 case 26:
7788 //pivot + lit + hflip
7789 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7790 //return error cannot pivot, lit, and flip
7791 break;
7792
7793 case 28:
7794 //lit + vh flip
7795 //return an error, cannot both rotate and VH flip
7796 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7797 break;
7798
7799 case 32: //gouraud
7800 //Probably not wort supporting.
7801 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7802 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7803 break;
7804
7805 case 0:
7806 //no effect.
7807 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7808 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7809 break;
7810
7811 default:
7812
7813 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7814
7815 }
7816 } //end if rotated
7817 } //end if not masked
7818 } //end if not stretched
7819
7820 //cleanup
7821
2/2
✓ Branch 0 taken 26562 times.
✓ Branch 1 taken 239187 times.
265749 if(subBmp)
7822 {
7823 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
7824 26562 destroy_bitmap(subBmp);
7825 26562 }
7826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 265749 times.
265749 if (sbmp != sourceBitmap)
7827 {
7828 destroy_bitmap(sbmp);
7829 }
7830 265749 }
7831
7832
7833
7834 113329 void bmp_do_blittor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
7835 {
7836 /*
7837 //sdci[1]=layer
7838 //sdci[2]=bitmap target
7839 //
7840 // -2 is the current Render Target
7841 // -1, this is the screen (framebuf).
7842 // 0: Render target 0
7843 // 1: Render target 1
7844 // 2: Render target 2
7845 // 3: Render target 3
7846 // 4: Render target 4
7847 // 5: Render target 5
7848 // 6: Render target 6
7849 // Otherwise: The pointer to a bitmap.
7850
7851 //sdci[3]=sourcex
7852 //sdci[4]=sourcey
7853 //sdci[5]=sourcew
7854 //sdci[6]=sourceh
7855 //sdci[7]=destx
7856 //sdci[8]=desty
7857 //sdci[9]=destw
7858 //sdci[10]=desth
7859 //sdci[11]=rotation/angle
7860 //scdi[12] = pivot cx
7861 //sdci[13] = pivot cy
7862 //scdi[14] = effect flags
7863 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
7864
7865 // ZScript-side constant values:
7866 const int32_t BITDX_NORMAL = 0;
7867 const int32_t BITDX_TRANS = 1; //Translucent
7868 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
7869 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
7870 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
7871 //Note: Some modes cannot be combined. if a combination is not supported, an error
7872 // detailing this will be shown in allegro.log.
7873
7874 //scdi[15] = litcolour
7875 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7876 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
7877
7878 //sdci[16]=mask
7879
7880 */
7881
7882 113329 int32_t srcyoffset = yoffset, srcxoffset = xoffset;
7883
7884 113329 int32_t usr_bitmap_index = sdci[2];
7885 339987 auto [bitmapIndex, is_user_bitmap] = resolveScriptingBitmapId(usr_bitmap_index);
7886
7887 113329 int32_t sx = sdci[3]/10000;
7888 113329 int32_t sy = sdci[4]/10000;
7889 113329 int32_t sw = sdci[5]/10000;
7890 113329 int32_t sh = sdci[6]/10000;
7891 113329 int32_t dx = sdci[7]/10000;
7892 113329 int32_t dy = sdci[8]/10000;
7893 113329 int32_t dw = sdci[9]/10000;
7894 113329 int32_t dh = sdci[10]/10000;
7895 113329 float rot = sdci[11]/10000;
7896 113329 int32_t cx = sdci[12]/10000;
7897 113329 int32_t cy = sdci[13]/10000;
7898 113329 int32_t mode = sdci[14]/10000;
7899 113329 int32_t litcolour = sdci[15]/10000;
7900 113329 bool masked = (sdci[16] != 0);
7901
7902 113329 int32_t ref = 0;
7903
7904
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (get_qr(qr_BROKEN_SCRIPTS_BITMAP_DRAW_ORIGIN))
7905 {
7906
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113326 times.
113329 if (is_user_bitmap)
7907 113326 srcyoffset = 0;
7908
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
7909
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if ( (bitmapIndex) != -2 && (bitmapIndex) != -1 ) srcyoffset = 0; //Don't crop.
7910
7911 113329 dx += xoffset;
7912 113329 dy += yoffset;
7913
7914 113329 sx += srcxoffset;
7915 113329 sy += srcyoffset;
7916 113329 }
7917 else
7918 {
7919 dx += xoffset;
7920 dy += yoffset;
7921
7922 sx += secondary_draw_origin_xoff;
7923 sy += secondary_draw_origin_yoff;
7924 }
7925
7926 113329 ref = sdci[DRAWCMD_BMP_TARGET];
7927
7928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if ( ref <= 0 )
7929 {
7930 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
7931 return;
7932 }
7933 113329 BITMAP *sourceBitmap = resolveScriptingBitmap(ref); //This can be the screen, as -1.
7934
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if(!sourceBitmap)
7935 {
7936 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
7937 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7938 return;
7939 }
7940
7941 113329 BITMAP *destBMP=NULL;
7942
7943
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
113329 switch(bitmapIndex)
7944 {
7945 // Current render target (RT_CURRENT).
7946 // This is the only reason we aren't using resolveScriptingBitmap for the target bitmap. All the other cases should be equivalent.
7947 case -2:
7948 {
7949 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
7950 if ( curr_rt >= 0 && curr_rt < 7 )
7951 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
7952 else destBMP = bmp; //screen
7953 break;
7954 }
7955 case -1:
7956 3 destBMP = bmp; //this is framebuf, by default
7957 3 break;
7958 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
7959 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
7960 //destBMP = framebuf; //Drawing to the screen.
7961 //break;
7962
7963 //1 through 6 are the old system bitmaps (Render Targets)
7964 case 0:
7965 case 1:
7966 case 2:
7967 case 3:
7968 case 4:
7969 case 5:
7970 case 6:
7971 {
7972 //This gets a render target.
7973 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
7974
7975 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
7976 //sdci[18] = bitmapIndex;
7977 break;
7978 }
7979 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
7980 default:
7981 {
7982 113326 auto& usr_bitmap = scb.get(usr_bitmap_index);
7983 113326 destBMP = usr_bitmap.u_bmp;
7984 //sdci[18] = usr_bitmap_index;
7985
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( !usr_bitmap.u_bmp )
7986 {
7987 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
7988 break;
7989 }
7990 }
7991 113326 }
7992
7993
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (!destBMP)
7994 {
7995 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
7996 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7997 return;
7998 }
7999
8000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 bool stretched = (sw != dw || sh != dh);
8001
8002 113329 BITMAP* newDest = sourceBitmap;
8003 113329 BITMAP* newSource = destBMP; //Flip them.
8004
8005 113329 BITMAP* subBmp = 0;
8006
8007
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if(rot != 0 || mode != 0)
8008 {
8009 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
8010 clear_bitmap(subBmp);
8011
8012 if(!subBmp)
8013 {
8014 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
8015 return;
8016 }
8017 }
8018
8019
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if (sx + sw > destBMP->w || sy + sh > destBMP->h)
8020 {
8021 3 newSource = create_bitmap_ex(8, sw, sh);
8022 3 clear_bitmap(newSource);
8023 3 blit(destBMP, newSource, sx, sy, 0, 0, std::min(destBMP->w-sx, sw), std::min(destBMP->h-sy, sh));
8024 3 sx = 0;
8025 3 sy = 0;
8026 3 }
8027 //dx = dx + xoffset; //don't do this here!
8028 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
8029
8030
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(stretched)
8031 {
8032 if(masked)
8033 { //stretched and masked
8034 if ( rot == 0 )
8035 { //if not rotated
8036 switch(mode)
8037 {
8038 case 1:
8039 //transparent
8040 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8041 draw_trans_sprite(newDest, subBmp, dx, dy);
8042 break;
8043
8044
8045 case 2:
8046 //pivot?
8047 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8048 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8049 //Pivoting requires two more args
8050 break;
8051
8052 case 3:
8053 //pivot + trans
8054 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8055 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8056 break;
8057
8058 case 4:
8059 //flip v
8060 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8061 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8062 break;
8063
8064 case 5:
8065 //trans + v flip
8066 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8067 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8068 break;
8069
8070 case 6:
8071 //pivot + v flip
8072 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8073 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8074 break;
8075
8076 case 8:
8077 //vlip h
8078 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8079 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8080 break;
8081
8082 case 9:
8083 //trans + h flip
8084 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8085 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8086 break;
8087
8088 case 10:
8089 //flip H and pivot
8090 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8091 //return error cannot pivot and h flip
8092 break;
8093
8094 case 12:
8095 //vh flip
8096 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8097 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8098 break;
8099
8100 case 13:
8101 //trans + vh flip
8102 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8103 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8104 break;
8105
8106 case 14:
8107 //pivot and vh flip
8108 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8109 //return error cannot both pivot and vh flip
8110 break;
8111
8112 case 16:
8113 //lit
8114 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8115 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8116 break;
8117
8118 case 18:
8119 //pivot, lit
8120 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8121 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8122 break;
8123
8124 case 20:
8125 //lit + v flip
8126 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8127 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8128 break;
8129
8130 case 22:
8131 //Pivot, vflip, lit
8132 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8133 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8134 break;
8135
8136 case 24:
8137 //lit + h flip
8138 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8139 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8140 break;
8141
8142 case 26:
8143 //pivot + lit + hflip
8144 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8145 //return error cannot pivot, lit, and flip
8146 break;
8147
8148 case 28:
8149 //lit + vh flip
8150 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8151 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8152 break;
8153
8154 case 32: //gouraud
8155 //Probably not wort supporting.
8156 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8157 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8158 break;
8159
8160 case 0:
8161 //no effect
8162 masked_stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8163 break;
8164
8165
8166 default:
8167 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8168
8169
8170 }
8171 } //end if not rotated
8172
8173 if ( rot != 0 ) //if rotated
8174 {
8175 switch(mode)
8176 {
8177 case 1:
8178 //transparent
8179 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8180 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8181
8182 break;
8183
8184 case 2:
8185 //pivot?
8186 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8187 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8188 //Pivoting requires two more args
8189 break;
8190
8191 case 3:
8192 //pivot + trans
8193 //return an error, cannot both rotate and pivot
8194 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8195 break;
8196
8197 case 4:
8198 //flip v
8199 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8200 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8201 break;
8202
8203 case 5:
8204 //trans + v flip
8205 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8206 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8207 break;
8208
8209 case 6:
8210 //pivot + v flip
8211 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8212 //return an error, cannot both rotate and pivot
8213 break;
8214
8215 case 8:
8216 //flip h
8217 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8218 //return an error, cannot both rotate and flip H
8219 break;
8220
8221 case 9:
8222 //trans + h flip
8223 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8224 //return an error, cannot rotate and flip a trans sprite
8225 break;
8226
8227 case 10:
8228 //flip H and pivot
8229 //return error cannot pivot and h flip
8230 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8231 break;
8232
8233 case 12:
8234 //vh flip
8235 //return an error, cannot rotate and VH flip a trans sprite
8236 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8237 break;
8238
8239 case 13:
8240 //trans + vh flip
8241 //return an error, cannot rotate and VH flip a trans sprite
8242 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8243 break;
8244
8245 case 14:
8246 //pivot and vh flip
8247 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8248 //return error cannot both pivot and vh flip
8249 break;
8250
8251 case 16:
8252 //lit
8253 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8254 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8255 break;
8256
8257 case 18:
8258 //pivot, lit
8259 //return an error, cannot both rotate and pivot
8260 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8261 break;
8262
8263 case 20:
8264 //lit + vflip
8265 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8266 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8267 break;
8268
8269 case 22:
8270 //Pivot, vflip, lit
8271 //return an error, cannot both rotate and pivot
8272 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8273 break;
8274
8275 case 24:
8276 //lit + h flip
8277 //return an error, cannot both rotate and H flip
8278 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8279 break;
8280
8281 case 26:
8282 //pivot + lit + hflip
8283 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8284 //return error cannot pivot, lit, and flip
8285 break;
8286
8287 case 28:
8288 //lit + vh flip
8289 //return an error, cannot both rotate and VH flip
8290 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8291 break;
8292
8293 case 32: //gouraud
8294 //Probably not wort supporting.
8295 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8296 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8297 break;
8298
8299 case 0:
8300 //no effect.
8301 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8302 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8303 break;
8304
8305 default:
8306 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8307
8308 }
8309 }
8310 } //end if stretched and masked
8311
8312 else //stretched, not masked
8313 {
8314
8315
8316 if ( rot == 0 ) //if not rotated
8317 {
8318 switch(mode)
8319 {
8320 case 1:
8321 //transparent
8322 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8323 draw_trans_sprite(newDest, subBmp, dx, dy);
8324 break;
8325
8326
8327 case 2:
8328 //pivot?
8329 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8330 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8331 //Pivoting requires two more args
8332 break;
8333
8334 case 3:
8335 //pivot + trans
8336 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8337 pivot_sprite_trans(newDest, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
8338 break;
8339
8340 case 4:
8341 //flip v
8342 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8343 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8344 break;
8345
8346 case 5:
8347 //trans + v flip
8348 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8349 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8350 break;
8351
8352 case 6:
8353 //pivot + v flip
8354 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8355 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8356 break;
8357
8358 case 8:
8359 //vlip h
8360 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8361 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8362 break;
8363
8364 case 9:
8365 //trans + h flip
8366 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8367 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8368 break;
8369
8370 case 10:
8371 //flip H and pivot
8372 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8373 //return error cannot pivot and h flip
8374 break;
8375
8376 case 12:
8377 //vh flip
8378 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8379 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8380 break;
8381
8382 case 13:
8383 //trans + vh flip
8384 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8385 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8386 break;
8387
8388 case 14:
8389 //pivot and vh flip
8390 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8391 //return error cannot both pivot and vh flip
8392 break;
8393
8394 case 16:
8395 //lit
8396 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8397 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8398 break;
8399
8400 case 18:
8401 //pivot, lit
8402 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8403 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8404 break;
8405
8406 case 20:
8407 //lit + v flip
8408 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8409 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8410 break;
8411
8412 case 22:
8413 //Pivot, vflip, lit
8414 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8415 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8416 break;
8417
8418 case 24:
8419 //lit + h flip
8420 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8421 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8422 break;
8423
8424 case 26:
8425 //pivot + lit + hflip
8426 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8427 //return error cannot pivot, lit, and flip
8428 break;
8429
8430 case 28:
8431 //lit + vh flip
8432 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8433 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8434 break;
8435
8436 case 32: //gouraud
8437 //Probably not wort supporting.
8438 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8439 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8440 break;
8441
8442 case 0:
8443 //no effect
8444 stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8445 break;
8446
8447
8448 default:
8449 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8450
8451
8452 }
8453 } //end if not rotated
8454
8455 if ( rot != 0 ) //if rotated
8456 {
8457 switch(mode)
8458 {
8459 case 1:
8460 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8461 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8462
8463 break;
8464
8465 case 2:
8466 //pivot?
8467 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8468 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8469 //Pivoting requires two more args
8470 break;
8471
8472 case 3:
8473 //pivot + trans
8474 //return an error, cannot both rotate and pivot
8475 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8476 break;
8477
8478 case 4:
8479 //flip v
8480 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8481 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8482 break;
8483
8484 case 5:
8485 //trans + v flip
8486 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8487 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8488 break;
8489
8490 case 6:
8491 //pivot + v flip
8492 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8493 //return an error, cannot both rotate and pivot
8494 break;
8495
8496 case 8:
8497 //flip h
8498 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8499 //return an error, cannot both rotate and flip H
8500 break;
8501
8502 case 9:
8503 //trans + h flip
8504 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8505 //return an error, cannot rotate and flip a trans sprite
8506 break;
8507
8508 case 10:
8509 //flip H and pivot
8510 //return error cannot pivot and h flip
8511 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8512 break;
8513
8514 case 12:
8515 //vh flip
8516 //return an error, cannot rotate and VH flip a trans sprite
8517 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8518 break;
8519
8520 case 13:
8521 //trans + vh flip
8522 //return an error, cannot rotate and VH flip a trans sprite
8523 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8524 break;
8525
8526 case 14:
8527 //pivot and vh flip
8528 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8529 //return error cannot both pivot and vh flip
8530 break;
8531
8532 case 16:
8533 //lit
8534 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8535 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8536 break;
8537
8538 case 18:
8539 //pivot, lit
8540 //return an error, cannot both rotate and pivot
8541 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8542 break;
8543
8544 case 20:
8545 //lit + vflip
8546 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8547 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8548 break;
8549
8550 case 22:
8551 //Pivot, vflip, lit
8552 //return an error, cannot both rotate and pivot
8553 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8554 break;
8555
8556 case 24:
8557 //lit + h flip
8558 //return an error, cannot both rotate and H flip
8559 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8560 break;
8561
8562 case 26:
8563 //pivot + lit + hflip
8564 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8565 //return error cannot pivot, lit, and flip
8566 break;
8567
8568 case 28:
8569 //lit + vh flip
8570 //return an error, cannot both rotate and VH flip
8571 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8572 break;
8573
8574 case 32: //gouraud
8575 //Probably not wort supporting.
8576 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8577 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8578 break;
8579
8580 case 0:
8581 //no effect.
8582 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8583 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8584 break;
8585
8586 default:
8587 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8588
8589 }
8590 }
8591
8592 } //end if stretched, but not masked
8593 }
8594 else //not stretched
8595 {
8596
8597
2/2
✓ Branch 0 taken 113326 times.
✓ Branch 1 taken 3 times.
113329 if(masked) //if masked, but not stretched
8598 {
8599
8600
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
113326 if ( rot == 0 ) //if not rotated
8601 {
8602
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 113326 times.
113326 switch(mode)
8603 {
8604 case 1:
8605 //transparent
8606 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8607 draw_trans_sprite(newDest, subBmp, dx, dy);
8608 break;
8609
8610
8611 case 2:
8612 //pivot?
8613 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8614 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8615 //Pivoting requires two more args
8616 break;
8617
8618 case 3:
8619 //pivot + trans
8620 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8621 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8622 break;
8623
8624 case 4:
8625 //flip v
8626 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8627 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8628 break;
8629
8630 case 5:
8631 //trans + v flip
8632 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8633 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8634 break;
8635
8636 case 6:
8637 //pivot + v flip
8638 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8639 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8640 break;
8641
8642 case 8:
8643 //vlip h
8644 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8645 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8646 break;
8647
8648 case 9:
8649 //trans + h flip
8650 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8651 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8652 break;
8653
8654 case 10:
8655 //flip H and pivot
8656 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8657 //return error cannot pivot and h flip
8658 break;
8659
8660 case 12:
8661 //vh flip
8662 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8663 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8664 break;
8665
8666 case 13:
8667 //trans + vh flip
8668 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8669 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8670 break;
8671
8672 case 14:
8673 //pivot and vh flip
8674 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8675 //return error cannot both pivot and vh flip
8676 break;
8677
8678 case 16:
8679 //lit
8680 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8681 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8682 break;
8683
8684 case 18:
8685 //pivot, lit
8686 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8687 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8688 break;
8689
8690 case 20:
8691 //lit + v flip
8692 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8693 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8694 break;
8695
8696 case 22:
8697 //Pivot, vflip, lit
8698 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8699 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8700 break;
8701
8702 case 24:
8703 //lit + h flip
8704 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8705 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8706 break;
8707
8708 case 26:
8709 //pivot + lit + hflip
8710 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8711 //return error cannot pivot, lit, and flip
8712 break;
8713
8714 case 28:
8715 //lit + vh flip
8716 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8717 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8718 break;
8719
8720 case 32: //gouraud
8721 //Probably not wort supporting.
8722 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8723 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8724 break;
8725
8726 case 0:
8727 //no effect
8728 113326 masked_blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8729 113326 break;
8730
8731
8732 default:
8733 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8734
8735
8736 }
8737 113326 } //end if not rotated
8738
8739
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( rot != 0 ) //if rotated
8740 {
8741 switch(mode)
8742 {
8743 case 1:
8744 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //transparent
8745 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8746
8747 break;
8748
8749 case 2:
8750 //pivot?
8751 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8752 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8753 //Pivoting requires two more args
8754 break;
8755
8756 case 3:
8757 //pivot + trans
8758 //return an error, cannot both rotate and pivot
8759 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8760 break;
8761
8762 case 4:
8763 //flip v
8764 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8765 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8766 break;
8767
8768 case 5:
8769 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
8770 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8771 break;
8772
8773 case 6:
8774 //pivot + v flip
8775 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8776 //return an error, cannot both rotate and pivot
8777 break;
8778
8779 case 8:
8780 //flip h
8781 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8782 //return an error, cannot both rotate and flip H
8783 break;
8784
8785 case 9:
8786 //trans + h flip
8787 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8788 //return an error, cannot rotate and flip a trans sprite
8789 break;
8790
8791 case 10:
8792 //flip H and pivot
8793 //return error cannot pivot and h flip
8794 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8795 break;
8796
8797 case 12:
8798 //vh flip
8799 //return an error, cannot rotate and VH flip a trans sprite
8800 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8801 break;
8802
8803 case 13:
8804 //trans + vh flip
8805 //return an error, cannot rotate and VH flip a trans sprite
8806 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8807 break;
8808
8809 case 14:
8810 //pivot and vh flip
8811 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8812 //return error cannot both pivot and vh flip
8813 break;
8814
8815 case 16:
8816 //lit
8817 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8818 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8819 break;
8820
8821 case 18:
8822 //pivot, lit
8823 //return an error, cannot both rotate and pivot
8824 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8825 break;
8826
8827 case 20:
8828 //lit + vflip
8829 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8830 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8831 break;
8832
8833 case 22:
8834 //Pivot, vflip, lit
8835 //return an error, cannot both rotate and pivot
8836 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8837 break;
8838
8839 case 24:
8840 //lit + h flip
8841 //return an error, cannot both rotate and H flip
8842 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8843 break;
8844
8845 case 26:
8846 //pivot + lit + hflip
8847 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8848 //return error cannot pivot, lit, and flip
8849 break;
8850
8851 case 28:
8852 //lit + vh flip
8853 //return an error, cannot both rotate and VH flip
8854 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8855 break;
8856
8857 case 32: //gouraud
8858 //Probably not wort supporting.
8859 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8860 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8861 break;
8862
8863 case 0:
8864 //no effect.
8865 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8866 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8867 break;
8868
8869 default:
8870 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8871
8872 }
8873 } //end rtated, masked
8874 113326 } //end if masked
8875
8876 else //not masked, and not stretched; just blit
8877 {
8878
8879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( rot == 0 ) //if not rotated
8880 {
8881
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
3 switch(mode)
8882 {
8883 case 1:
8884 //transparent
8885 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8886 draw_trans_sprite(newDest, subBmp, dx, dy);
8887 break;
8888
8889
8890 case 2:
8891 //pivot?
8892 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8893 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8894 //Pivoting requires two more args
8895 break;
8896
8897 case 3:
8898 //pivot + trans
8899 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8900 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8901 break;
8902
8903 case 4:
8904 //flip v
8905 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8906 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8907 break;
8908
8909 case 5:
8910 //trans + v flip
8911 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8912 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8913 break;
8914
8915 case 6:
8916 //pivot + v flip
8917 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8918 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8919 break;
8920
8921 case 8:
8922 //vlip h
8923 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8924 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8925 break;
8926
8927 case 9:
8928 //trans + h flip
8929 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8930 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8931 break;
8932
8933 case 10:
8934 //flip H and pivot
8935 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8936 //return error cannot pivot and h flip
8937 break;
8938
8939 case 12:
8940 //vh flip
8941 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8942 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8943 break;
8944
8945 case 13:
8946 //trans + vh flip
8947 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8948 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8949 break;
8950
8951 case 14:
8952 //pivot and vh flip
8953 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8954 //return error cannot both pivot and vh flip
8955 break;
8956
8957 case 16:
8958 //lit
8959 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8960 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8961 break;
8962
8963 case 18:
8964 //pivot, lit
8965 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8966 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8967 break;
8968
8969 case 20:
8970 //lit + v flip
8971 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8972 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8973 break;
8974
8975 case 22:
8976 //Pivot, vflip, lit
8977 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8978 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8979 break;
8980
8981 case 24:
8982 //lit + h flip
8983 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8984 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8985 break;
8986
8987 case 26:
8988 //pivot + lit + hflip
8989 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8990 //return error cannot pivot, lit, and flip
8991 break;
8992
8993 case 28:
8994 //lit + vh flip
8995 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8996 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8997 break;
8998
8999 case 32: //gouraud
9000 //Probably not wort supporting.
9001 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9002 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9003 break;
9004
9005 case 0:
9006 //no effect
9007 3 blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
9008 3 break;
9009
9010
9011 default:
9012 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9013
9014
9015 }
9016 3 } //end if not rotated
9017
9018
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( rot != 0 ) //if rotated
9019 {
9020 switch(mode)
9021 {
9022 case 1:
9023 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);//transparent
9024 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9025
9026 break;
9027
9028 case 2:
9029 //pivot?
9030 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9031 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9032 //Pivoting requires two more args
9033 break;
9034
9035 case 3:
9036 //pivot + trans
9037 //return an error, cannot both rotate and pivot
9038 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9039 break;
9040
9041 case 4:
9042 //flip v
9043 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9044 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9045 break;
9046
9047 case 5:
9048 //trans + v flip
9049 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9050 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9051 break;
9052
9053 case 6:
9054 //pivot + v flip
9055 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9056 //return an error, cannot both rotate and pivot
9057 break;
9058
9059 case 8:
9060 //flip h
9061 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
9062 //return an error, cannot both rotate and flip H
9063 break;
9064
9065 case 9:
9066 //trans + h flip
9067 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
9068 //return an error, cannot rotate and flip a trans sprite
9069 break;
9070
9071 case 10:
9072 //flip H and pivot
9073 //return error cannot pivot and h flip
9074 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
9075 break;
9076
9077 case 12:
9078 //vh flip
9079 //return an error, cannot rotate and VH flip a trans sprite
9080 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9081 break;
9082
9083 case 13:
9084 //trans + vh flip
9085 //return an error, cannot rotate and VH flip a trans sprite
9086 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9087 break;
9088
9089 case 14:
9090 //pivot and vh flip
9091 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9092 //return error cannot both pivot and vh flip
9093 break;
9094
9095 case 16:
9096 //lit
9097 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9098 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9099 break;
9100
9101 case 18:
9102 //pivot, lit
9103 //return an error, cannot both rotate and pivot
9104 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9105 break;
9106
9107 case 20:
9108 //lit + vflip
9109 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9110 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9111 break;
9112
9113 case 22:
9114 //Pivot, vflip, lit
9115 //return an error, cannot both rotate and pivot
9116 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9117 break;
9118
9119 case 24:
9120 //lit + h flip
9121 //return an error, cannot both rotate and H flip
9122 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
9123 break;
9124
9125 case 26:
9126 //pivot + lit + hflip
9127 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
9128 //return error cannot pivot, lit, and flip
9129 break;
9130
9131 case 28:
9132 //lit + vh flip
9133 //return an error, cannot both rotate and VH flip
9134 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9135 break;
9136
9137 case 32: //gouraud
9138 //Probably not wort supporting.
9139 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9140 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9141 break;
9142
9143 case 0:
9144 //no effect.
9145 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9146 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9147 break;
9148
9149 default:
9150 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9151
9152 }
9153 } //end if rotated
9154 } //end if not masked
9155 } //end if not stretched
9156
9157 //cleanup
9158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(subBmp)
9159 {
9160 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
9161 destroy_bitmap(subBmp);
9162 }
9163
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113326 times.
113329 if(newSource != destBMP)
9164 {
9165 3 destroy_bitmap(newSource);
9166 3 }
9167 113329 }
9168
9169 void do_tileblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp, char const* funcstr)
9170 {
9171 /*
9172 //sdci[1]=layer
9173 //sdci[2]=tile
9174 //sdci[3]=cset
9175 //sdci[4]=sourcex
9176 //sdci[5]=sourcey
9177 //sdci[6]=sourcew
9178 //sdci[7]=sourceh
9179 //sdci[8]=destx
9180 //sdci[9]=desty
9181 //sdci[10]=destw
9182 //sdci[11]=desth
9183 //sdci[12]=rotation/angle
9184 //scdi[13] = pivot cx
9185 //sdci[14] = pivot cy
9186 //scdi[15] = effect flags
9187
9188 // ZScript-side constant values:
9189 const int32_t BITDX_NORMAL = 0;
9190 const int32_t BITDX_TRANS = 1; //Translucent
9191 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
9192 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
9193 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
9194 //Note: Some modes cannot be combined. if a combination is not supported, an error
9195 // detailing this will be shown in allegro.log.
9196
9197 //scdi[16] = litcolour
9198 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9199 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
9200
9201 //sdci[17]=mask
9202 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
9203
9204 */
9205
9206 int32_t tile = sdci[2]/10000;
9207 int32_t cset = WRAP_CS(sdci[3]/10000);
9208
9209 int32_t sx = sdci[4]/10000;
9210 int32_t sy = sdci[5]/10000;
9211 int32_t sw = sdci[6]/10000;
9212 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
9213 int32_t sh = sdci[7]/10000;
9214 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
9215 int32_t dx = sdci[8]/10000;
9216 int32_t dy = sdci[9]/10000;
9217 int32_t dw = sdci[10]/10000;
9218 int32_t dh = sdci[11]/10000;
9219 float rot = sdci[12]/10000;
9220 int32_t cx = sdci[13]/10000;
9221 int32_t cy = sdci[14]/10000;
9222 int32_t mode = sdci[15]/10000;
9223 int32_t litcolour = sdci[16]/10000;
9224 bool masked = (sdci[17] != 0);
9225
9226 int32_t ref = 0;
9227
9228 if ( is_bmp && (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
9229 //Do we need to also check the render target and do the same thing if the
9230 //dest == -2 and the render target is not RT_SCREEN?
9231 dx += xoffset;
9232 dy += yoffset;
9233
9234 BITMAP *destbmp = nullptr;
9235 if(is_bmp)
9236 {
9237 ref = sdci[DRAWCMD_BMP_TARGET];
9238
9239 if ( ref <= 0 )
9240 {
9241 Z_scripterrlog("%s wanted to use to an invalid dest bitmap id: %d. Aborting.\n", funcstr, ref);
9242 return;
9243 }
9244 destbmp = resolveScriptingBitmap(ref);
9245 if(!destbmp)
9246 {
9247 Z_message("Warning: %s dest bitmap %d contains invalid data or is not initialized.\n", ref);
9248 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
9249 return;
9250 }
9251 }
9252 else destbmp = bmp;
9253
9254 bool stretched = (sw != dw || sh != dh);
9255
9256 BITMAP* srcbmp = create_bitmap_ex(8, sw, sh);
9257 //Draw tiles to srcbmp
9258 {
9259 clear_bitmap(srcbmp);
9260 int tx = 0, ty = 0;
9261 if(sx < 0)
9262 tx = (sx-15)/16;
9263 else if(sx > 15)
9264 tx = sx/16;
9265 if(sy < 0)
9266 ty = (sy-15)/16;
9267 else if(sy > 15)
9268 ty = sy/16;
9269
9270 int gxoff = -wrap(sx,0,15), gyoff = -wrap(sy,0,15);
9271 for(int ix = 0; ix <= sw; ix += 16)
9272 {
9273 for(int iy = 0; iy <= sh; iy += 16)
9274 {
9275 int t = tile+(tx+ix/16);
9276 int rowdiff = TILEROW(t) - TILEROW(tile);
9277 t += rowdiff * (sh/16) * TILES_PER_ROW;
9278 t += (ty+iy/16)*TILES_PER_ROW;
9279 overtile16(srcbmp, t, ix+gxoff, iy+gyoff, cset, 0);
9280 }
9281 }
9282
9283 sx = sy = 0;
9284 }
9285
9286 BITMAP* subBmp = nullptr;
9287
9288 if(rot != 0 || mode != 0)
9289 {
9290 subBmp = create_bitmap_ex(8,destbmp->w, destbmp->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
9291 clear_bitmap(subBmp);
9292
9293 if(!subBmp)
9294 {
9295 Z_scripterrlog("%s failed to create a sub-bitmap to use for %s. Aborting.\n", funcstr, "rotation");
9296 return;
9297 }
9298 }
9299
9300 //dx = dx + xoffset; //don't do this here!
9301 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
9302
9303 if(stretched)
9304 {
9305 if(masked)
9306 { //stretched and masked
9307 if ( rot == 0 )
9308 { //if not rotated
9309 switch(mode)
9310 {
9311 case 1:
9312 //transparent
9313 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9314 draw_trans_sprite(destbmp, subBmp, dx, dy);
9315 break;
9316
9317
9318 case 2:
9319 //pivot?
9320 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9321 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9322 //Pivoting requires two more args
9323 break;
9324
9325 case 3:
9326 //pivot + trans
9327 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9328 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9329 break;
9330
9331 case 4:
9332 //flip v
9333 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9334 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9335 break;
9336
9337 case 5:
9338 //trans + v flip
9339 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9340 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9341 break;
9342
9343 case 6:
9344 //pivot + v flip
9345 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9346 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9347 break;
9348
9349 case 8:
9350 //vlip h
9351 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9352 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9353 break;
9354
9355 case 9:
9356 //trans + h flip
9357 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9358 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9359 break;
9360
9361 case 10:
9362 //flip H and pivot
9363 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9364 //return error cannot pivot and h flip
9365 break;
9366
9367 case 12:
9368 //vh flip
9369 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9370 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9371 break;
9372
9373 case 13:
9374 //trans + vh flip
9375 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9376 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9377 break;
9378
9379 case 14:
9380 //pivot and vh flip
9381 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9382 //return error cannot both pivot and vh flip
9383 break;
9384
9385 case 16:
9386 //lit
9387 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9388 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9389 break;
9390
9391 case 18:
9392 //pivot, lit
9393 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9394 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9395 break;
9396
9397 case 20:
9398 //lit + v flip
9399 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9400 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9401 break;
9402
9403 case 22:
9404 //Pivot, vflip, lit
9405 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9406 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9407 break;
9408
9409 case 24:
9410 //lit + h flip
9411 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9412 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9413 break;
9414
9415 case 26:
9416 //pivot + lit + hflip
9417 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9418 //return error cannot pivot, lit, and flip
9419 break;
9420
9421 case 28:
9422 //lit + vh flip
9423 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9424 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9425 break;
9426
9427 case 32: //gouraud
9428 //Probably not wort supporting.
9429 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9430 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9431 break;
9432
9433 case 0:
9434 //no effect
9435 masked_stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9436 break;
9437
9438
9439 default:
9440 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9441
9442
9443 }
9444 } //end if not rotated
9445
9446 if ( rot != 0 ) //if rotated
9447 {
9448 switch(mode)
9449 {
9450 case 1:
9451 //transparent
9452 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9453 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9454
9455 break;
9456
9457 case 2:
9458 //pivot?
9459 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9460 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9461 //Pivoting requires two more args
9462 break;
9463
9464 case 3:
9465 //pivot + trans
9466 //return an error, cannot both rotate and pivot
9467 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9468 break;
9469
9470 case 4:
9471 //flip v
9472 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9473 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9474 break;
9475
9476 case 5:
9477 //trans + v flip
9478 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9479 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9480 break;
9481
9482 case 6:
9483 //pivot + v flip
9484 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9485 //return an error, cannot both rotate and pivot
9486 break;
9487
9488 case 8:
9489 //flip h
9490 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9491 //return an error, cannot both rotate and flip H
9492 break;
9493
9494 case 9:
9495 //trans + h flip
9496 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9497 //return an error, cannot rotate and flip a trans sprite
9498 break;
9499
9500 case 10:
9501 //flip H and pivot
9502 //return error cannot pivot and h flip
9503 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9504 break;
9505
9506 case 12:
9507 //vh flip
9508 //return an error, cannot rotate and VH flip a trans sprite
9509 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9510 break;
9511
9512 case 13:
9513 //trans + vh flip
9514 //return an error, cannot rotate and VH flip a trans sprite
9515 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9516 break;
9517
9518 case 14:
9519 //pivot and vh flip
9520 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9521 //return error cannot both pivot and vh flip
9522 break;
9523
9524 case 16:
9525 //lit
9526 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9527 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9528 break;
9529
9530 case 18:
9531 //pivot, lit
9532 //return an error, cannot both rotate and pivot
9533 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9534 break;
9535
9536 case 20:
9537 //lit + vflip
9538 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9539 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9540 break;
9541
9542 case 22:
9543 //Pivot, vflip, lit
9544 //return an error, cannot both rotate and pivot
9545 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9546 break;
9547
9548 case 24:
9549 //lit + h flip
9550 //return an error, cannot both rotate and H flip
9551 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9552 break;
9553
9554 case 26:
9555 //pivot + lit + hflip
9556 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9557 //return error cannot pivot, lit, and flip
9558 break;
9559
9560 case 28:
9561 //lit + vh flip
9562 //return an error, cannot both rotate and VH flip
9563 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9564 break;
9565
9566 case 32: //gouraud
9567 //Probably not wort supporting.
9568 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9569 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9570 break;
9571
9572 case 0:
9573 //no effect.
9574 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9575 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9576 break;
9577
9578 default:
9579 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9580
9581 }
9582 }
9583 } //end if stretched and masked
9584
9585 else //stretched, not masked
9586 {
9587
9588
9589 if ( rot == 0 ) //if not rotated
9590 {
9591 switch(mode)
9592 {
9593 case 1:
9594 //transparent
9595 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9596 draw_trans_sprite(destbmp, subBmp, dx, dy);
9597 break;
9598
9599
9600 case 2:
9601 //pivot?
9602 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9603 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9604 //Pivoting requires two more args
9605 break;
9606
9607 case 3:
9608 //pivot + trans
9609 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9610 pivot_sprite_trans(destbmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
9611 break;
9612
9613 case 4:
9614 //flip v
9615 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9616 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9617 break;
9618
9619 case 5:
9620 //trans + v flip
9621 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9622 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9623 break;
9624
9625 case 6:
9626 //pivot + v flip
9627 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9628 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9629 break;
9630
9631 case 8:
9632 //vlip h
9633 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9634 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9635 break;
9636
9637 case 9:
9638 //trans + h flip
9639 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9640 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9641 break;
9642
9643 case 10:
9644 //flip H and pivot
9645 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9646 //return error cannot pivot and h flip
9647 break;
9648
9649 case 12:
9650 //vh flip
9651 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9652 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9653 break;
9654
9655 case 13:
9656 //trans + vh flip
9657 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9658 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9659 break;
9660
9661 case 14:
9662 //pivot and vh flip
9663 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9664 //return error cannot both pivot and vh flip
9665 break;
9666
9667 case 16:
9668 //lit
9669 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9670 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9671 break;
9672
9673 case 18:
9674 //pivot, lit
9675 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9676 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9677 break;
9678
9679 case 20:
9680 //lit + v flip
9681 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9682 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9683 break;
9684
9685 case 22:
9686 //Pivot, vflip, lit
9687 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9688 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9689 break;
9690
9691 case 24:
9692 //lit + h flip
9693 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9694 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9695 break;
9696
9697 case 26:
9698 //pivot + lit + hflip
9699 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9700 //return error cannot pivot, lit, and flip
9701 break;
9702
9703 case 28:
9704 //lit + vh flip
9705 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9706 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9707 break;
9708
9709 case 32: //gouraud
9710 //Probably not wort supporting.
9711 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9712 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9713 break;
9714
9715 case 0:
9716 //no effect
9717 stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9718 break;
9719
9720
9721 default:
9722 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9723
9724
9725 }
9726 } //end if not rotated
9727
9728 if ( rot != 0 ) //if rotated
9729 {
9730 switch(mode)
9731 {
9732 case 1:
9733 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9734 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9735
9736 break;
9737
9738 case 2:
9739 //pivot?
9740 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9741 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9742 //Pivoting requires two more args
9743 break;
9744
9745 case 3:
9746 //pivot + trans
9747 //return an error, cannot both rotate and pivot
9748 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9749 break;
9750
9751 case 4:
9752 //flip v
9753 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9754 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9755 break;
9756
9757 case 5:
9758 //trans + v flip
9759 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9760 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9761 break;
9762
9763 case 6:
9764 //pivot + v flip
9765 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9766 //return an error, cannot both rotate and pivot
9767 break;
9768
9769 case 8:
9770 //flip h
9771 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9772 //return an error, cannot both rotate and flip H
9773 break;
9774
9775 case 9:
9776 //trans + h flip
9777 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9778 //return an error, cannot rotate and flip a trans sprite
9779 break;
9780
9781 case 10:
9782 //flip H and pivot
9783 //return error cannot pivot and h flip
9784 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9785 break;
9786
9787 case 12:
9788 //vh flip
9789 //return an error, cannot rotate and VH flip a trans sprite
9790 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9791 break;
9792
9793 case 13:
9794 //trans + vh flip
9795 //return an error, cannot rotate and VH flip a trans sprite
9796 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9797 break;
9798
9799 case 14:
9800 //pivot and vh flip
9801 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9802 //return error cannot both pivot and vh flip
9803 break;
9804
9805 case 16:
9806 //lit
9807 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9808 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9809 break;
9810
9811 case 18:
9812 //pivot, lit
9813 //return an error, cannot both rotate and pivot
9814 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9815 break;
9816
9817 case 20:
9818 //lit + vflip
9819 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9820 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9821 break;
9822
9823 case 22:
9824 //Pivot, vflip, lit
9825 //return an error, cannot both rotate and pivot
9826 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9827 break;
9828
9829 case 24:
9830 //lit + h flip
9831 //return an error, cannot both rotate and H flip
9832 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9833 break;
9834
9835 case 26:
9836 //pivot + lit + hflip
9837 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9838 //return error cannot pivot, lit, and flip
9839 break;
9840
9841 case 28:
9842 //lit + vh flip
9843 //return an error, cannot both rotate and VH flip
9844 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9845 break;
9846
9847 case 32: //gouraud
9848 //Probably not wort supporting.
9849 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9850 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9851 break;
9852
9853 case 0:
9854 //no effect.
9855 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9856 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9857 break;
9858
9859 default:
9860 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9861
9862 }
9863 }
9864
9865 } //end if stretched, but not masked
9866 }
9867 else //not stretched
9868 {
9869
9870 if(masked) //if masked, but not stretched
9871 {
9872
9873 if ( rot == 0 ) //if not rotated
9874 {
9875 switch(mode)
9876 {
9877 case 1:
9878 //transparent
9879 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9880 draw_trans_sprite(destbmp, subBmp, dx, dy);
9881 break;
9882
9883
9884 case 2:
9885 //pivot?
9886 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9887 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9888 //Pivoting requires two more args
9889 break;
9890
9891 case 3:
9892 //pivot + trans
9893 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9894 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9895 break;
9896
9897 case 4:
9898 //flip v
9899 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9900 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9901 break;
9902
9903 case 5:
9904 //trans + v flip
9905 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9906 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9907 break;
9908
9909 case 6:
9910 //pivot + v flip
9911 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9912 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9913 break;
9914
9915 case 8:
9916 //vlip h
9917 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9918 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9919 break;
9920
9921 case 9:
9922 //trans + h flip
9923 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9924 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9925 break;
9926
9927 case 10:
9928 //flip H and pivot
9929 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9930 //return error cannot pivot and h flip
9931 break;
9932
9933 case 12:
9934 //vh flip
9935 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9936 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9937 break;
9938
9939 case 13:
9940 //trans + vh flip
9941 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9942 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9943 break;
9944
9945 case 14:
9946 //pivot and vh flip
9947 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9948 //return error cannot both pivot and vh flip
9949 break;
9950
9951 case 16:
9952 //lit
9953 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9954 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9955 break;
9956
9957 case 18:
9958 //pivot, lit
9959 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9960 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9961 break;
9962
9963 case 20:
9964 //lit + v flip
9965 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9966 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9967 break;
9968
9969 case 22:
9970 //Pivot, vflip, lit
9971 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9972 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9973 break;
9974
9975 case 24:
9976 //lit + h flip
9977 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9978 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9979 break;
9980
9981 case 26:
9982 //pivot + lit + hflip
9983 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9984 //return error cannot pivot, lit, and flip
9985 break;
9986
9987 case 28:
9988 //lit + vh flip
9989 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9990 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9991 break;
9992
9993 case 32: //gouraud
9994 //Probably not wort supporting.
9995 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9996 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9997 break;
9998
9999 case 0:
10000 //no effect
10001 masked_blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
10002 break;
10003
10004
10005 default:
10006 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10007
10008
10009 }
10010 } //end if not rotated
10011
10012 if ( rot != 0 ) //if rotated
10013 {
10014 switch(mode)
10015 {
10016 case 1:
10017 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
10018 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10019
10020 break;
10021
10022 case 2:
10023 //pivot?
10024 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10025 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10026 //Pivoting requires two more args
10027 break;
10028
10029 case 3:
10030 //pivot + trans
10031 //return an error, cannot both rotate and pivot
10032 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10033 break;
10034
10035 case 4:
10036 //flip v
10037 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10038 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10039 break;
10040
10041 case 5:
10042 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
10043 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10044 break;
10045
10046 case 6:
10047 //pivot + v flip
10048 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10049 //return an error, cannot both rotate and pivot
10050 break;
10051
10052 case 8:
10053 //flip h
10054 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10055 //return an error, cannot both rotate and flip H
10056 break;
10057
10058 case 9:
10059 //trans + h flip
10060 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
10061 //return an error, cannot rotate and flip a trans sprite
10062 break;
10063
10064 case 10:
10065 //flip H and pivot
10066 //return error cannot pivot and h flip
10067 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10068 break;
10069
10070 case 12:
10071 //vh flip
10072 //return an error, cannot rotate and VH flip a trans sprite
10073 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10074 break;
10075
10076 case 13:
10077 //trans + vh flip
10078 //return an error, cannot rotate and VH flip a trans sprite
10079 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10080 break;
10081
10082 case 14:
10083 //pivot and vh flip
10084 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10085 //return error cannot both pivot and vh flip
10086 break;
10087
10088 case 16:
10089 //lit
10090 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10091 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10092 break;
10093
10094 case 18:
10095 //pivot, lit
10096 //return an error, cannot both rotate and pivot
10097 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10098 break;
10099
10100 case 20:
10101 //lit + vflip
10102 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10103 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10104 break;
10105
10106 case 22:
10107 //Pivot, vflip, lit
10108 //return an error, cannot both rotate and pivot
10109 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10110 break;
10111
10112 case 24:
10113 //lit + h flip
10114 //return an error, cannot both rotate and H flip
10115 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10116 break;
10117
10118 case 26:
10119 //pivot + lit + hflip
10120 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10121 //return error cannot pivot, lit, and flip
10122 break;
10123
10124 case 28:
10125 //lit + vh flip
10126 //return an error, cannot both rotate and VH flip
10127 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10128 break;
10129
10130 case 32: //gouraud
10131 //Probably not wort supporting.
10132 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
10133 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10134 break;
10135
10136 case 0:
10137 //no effect.
10138 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10139 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10140 break;
10141
10142 default:
10143 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10144
10145 }
10146 } //end rtated, masked
10147 } //end if masked
10148
10149 else //not masked, and not stretched; just blit
10150 {
10151
10152 if ( rot == 0 ) //if not rotated
10153 {
10154 switch(mode)
10155 {
10156 case 1:
10157 //transparent
10158 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10159 draw_trans_sprite(destbmp, subBmp, dx, dy);
10160 break;
10161
10162
10163 case 2:
10164 //pivot?
10165 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10166 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10167 //Pivoting requires two more args
10168 break;
10169
10170 case 3:
10171 //pivot + trans
10172 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10173 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10174 break;
10175
10176 case 4:
10177 //flip v
10178 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10179 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
10180 break;
10181
10182 case 5:
10183 //trans + v flip
10184 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10185 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
10186 break;
10187
10188 case 6:
10189 //pivot + v flip
10190 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10191 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10192 break;
10193
10194 case 8:
10195 //vlip h
10196 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10197 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
10198 break;
10199
10200 case 9:
10201 //trans + h flip
10202 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10203 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
10204 break;
10205
10206 case 10:
10207 //flip H and pivot
10208 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10209 //return error cannot pivot and h flip
10210 break;
10211
10212 case 12:
10213 //vh flip
10214 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10215 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
10216 break;
10217
10218 case 13:
10219 //trans + vh flip
10220 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10221 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
10222 break;
10223
10224 case 14:
10225 //pivot and vh flip
10226 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10227 //return error cannot both pivot and vh flip
10228 break;
10229
10230 case 16:
10231 //lit
10232 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10233 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
10234 break;
10235
10236 case 18:
10237 //pivot, lit
10238 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10239 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10240 break;
10241
10242 case 20:
10243 //lit + v flip
10244 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10245 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
10246 break;
10247
10248 case 22:
10249 //Pivot, vflip, lit
10250 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10251 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10252 break;
10253
10254 case 24:
10255 //lit + h flip
10256 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10257 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
10258 break;
10259
10260 case 26:
10261 //pivot + lit + hflip
10262 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
10263 //return error cannot pivot, lit, and flip
10264 break;
10265
10266 case 28:
10267 //lit + vh flip
10268 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10269 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
10270 break;
10271
10272 case 32: //gouraud
10273 //Probably not wort supporting.
10274 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10275 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10276 break;
10277
10278 case 0:
10279 //no effect
10280 blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
10281 break;
10282
10283
10284 default:
10285 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10286
10287
10288 }
10289 } //end if not rotated
10290
10291 if ( rot != 0 ) //if rotated
10292 {
10293 switch(mode)
10294 {
10295 case 1:
10296 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
10297 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10298
10299 break;
10300
10301 case 2:
10302 //pivot?
10303 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10304 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10305 //Pivoting requires two more args
10306 break;
10307
10308 case 3:
10309 //pivot + trans
10310 //return an error, cannot both rotate and pivot
10311 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10312 break;
10313
10314 case 4:
10315 //flip v
10316 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10317 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10318 break;
10319
10320 case 5:
10321 //trans + v flip
10322 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10323 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10324 break;
10325
10326 case 6:
10327 //pivot + v flip
10328 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10329 //return an error, cannot both rotate and pivot
10330 break;
10331
10332 case 8:
10333 //flip h
10334 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10335 //return an error, cannot both rotate and flip H
10336 break;
10337
10338 case 9:
10339 //trans + h flip
10340 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
10341 //return an error, cannot rotate and flip a trans sprite
10342 break;
10343
10344 case 10:
10345 //flip H and pivot
10346 //return error cannot pivot and h flip
10347 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10348 break;
10349
10350 case 12:
10351 //vh flip
10352 //return an error, cannot rotate and VH flip a trans sprite
10353 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10354 break;
10355
10356 case 13:
10357 //trans + vh flip
10358 //return an error, cannot rotate and VH flip a trans sprite
10359 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10360 break;
10361
10362 case 14:
10363 //pivot and vh flip
10364 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10365 //return error cannot both pivot and vh flip
10366 break;
10367
10368 case 16:
10369 //lit
10370 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10371 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10372 break;
10373
10374 case 18:
10375 //pivot, lit
10376 //return an error, cannot both rotate and pivot
10377 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10378 break;
10379
10380 case 20:
10381 //lit + vflip
10382 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10383 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10384 break;
10385
10386 case 22:
10387 //Pivot, vflip, lit
10388 //return an error, cannot both rotate and pivot
10389 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10390 break;
10391
10392 case 24:
10393 //lit + h flip
10394 //return an error, cannot both rotate and H flip
10395 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10396 break;
10397
10398 case 26:
10399 //pivot + lit + hflip
10400 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10401 //return error cannot pivot, lit, and flip
10402 break;
10403
10404 case 28:
10405 //lit + vh flip
10406 //return an error, cannot both rotate and VH flip
10407 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10408 break;
10409
10410 case 32: //gouraud
10411 //Probably not wort supporting.
10412 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10413 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10414 break;
10415
10416 case 0:
10417 //no effect.
10418 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10419 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10420 break;
10421
10422 default:
10423 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10424
10425 }
10426 } //end if rotated
10427 } //end if not masked
10428 } //end if not stretched
10429
10430 //cleanup
10431 if(subBmp)
10432 {
10433 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
10434 destroy_bitmap(subBmp);
10435 }
10436 destroy_bitmap(srcbmp);
10437 }
10438
10439 void do_comboblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp)
10440 {
10441 //sdci[2]: combo -> tile
10442 int cid = sdci[2]/10000;
10443 if(unsigned(cid) >= MAXCOMBOS)
10444 {
10445 Z_scripterrlog("ComboBlit tried to draw invalid combo id '%d'\n", cid);
10446 return;
10447 }
10448 sdci[2] = GET_DRAWING_COMBO(cid).tile * 10000;
10449 do_tileblit(bmp, sdci, xoffset, yoffset, is_bmp, "ComboBlit()");
10450 }
10451
10452 void bmp_do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10453 {
10454
10455 //sdci[1]=layer
10456 //sdci[2]=pos[12]
10457 //sdci[3]=uv[8]
10458 //sdci[4]=color[4]
10459 //sdci[5]=size[2]
10460 //sdci[6]=flip
10461 //sdci[7]=tile/combo
10462 //sdci[8]=polytype
10463 //sdci[9] = other bitmap as texture
10464 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10465 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10466 {
10467 Z_scripterrlog("bitmap->Quad3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10468 return;
10469 }
10470 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10471 if ( refbmp == NULL ) return;
10472
10473 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10474
10475 if(!v_ptr)
10476 {
10477 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
10478 return;
10479 }
10480
10481 std::vector<int32_t> &v = *v_ptr;
10482
10483 if(v.empty())
10484 return;
10485
10486 int32_t* pos = &v[0];
10487 int32_t* uv = &v[12];
10488 int32_t* col = &v[20];
10489 int32_t* size = &v[24];
10490
10491 int32_t w = size[0]; //magic numerical constants... yuck.
10492 int32_t h = size[1];
10493 int32_t flip = (sdci[6]/10000)&3;
10494 int32_t tile = sdci[7]/10000;
10495 int32_t polytype = sdci[8]/10000;
10496 int32_t quad_render_source = sdci[9];
10497 Z_scripterrlog("Quad3D texture is %d\n", quad_render_source);
10498
10499 polytype = vbound(polytype, 0, 14);
10500
10501 int32_t tex_width = w*16;
10502 int32_t tex_height = h*16;
10503
10504 bool mustDestroyBmp = false;
10505 BITMAP *tex=NULL;
10506
10507
10508 bool tex_is_bitmap = ( sdci[9] != 0 );
10509 //Z_scripterrlog("sdci[9] is %d\n", quad_render_source);
10510 //Z_scripterrlog("sdci[DRAWCMD_BMP_TARGET] is %d\n", sdci[DRAWCMD_BMP_TARGET]);
10511 BITMAP *bmptexture;
10512
10513 if ( tex_is_bitmap ) bmptexture = resolveScriptingBitmap(quad_render_source);
10514
10515 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10516
10517
10518 if ( !tex_is_bitmap )
10519 {
10520 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10521
10522 if(!tex)
10523 {
10524 mustDestroyBmp = true;
10525 tex = create_bitmap_ex(8, tex_width, tex_height);
10526 clear_bitmap(tex);
10527 }
10528 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10529 {
10530 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10531 return; //non power of two error
10532 }
10533 if(tile > 0) // TILE
10534 {
10535 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10536 }
10537 else // COMBO
10538 {
10539 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
10540 const int32_t tiletodraw = combo_tile(c, 0, 0);
10541 flip = flip ^ c.flip;
10542
10543 if(!(c.animflags & AF_EDITOR_ONLY))
10544 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10545 }
10546
10547 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10548 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10549 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10550 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10551
10552 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
10553 if(mustDestroyBmp)
10554 destroy_bitmap(tex);
10555 }
10556 else
10557 {
10558
10559 if ( !bmptexture )
10560 {
10561 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Quad3D()");
10562 tex_is_bitmap = 0;
10563 return;
10564 }
10565 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10566 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10567 if ( !isPowerOfTwo(h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10568 if ( !isPowerOfTwo(w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10569
10570 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10571 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10572 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10573 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10574
10575 BITMAP *foo = create_bitmap_ex(8, 256, 176);
10576
10577 //quad3d_f(refbmp, polytype, foo, &V1, &V2, &V3, &V4);
10578 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
10579 destroy_bitmap(foo);
10580
10581 }
10582
10583
10584
10585 }
10586
10587
10588
10589 void bmp_do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10590 {
10591 //sdci[1]=layer
10592 //sdci[2]=pos[9]
10593 //sdci[3]=uv[6]
10594 //sdci[4]=color[3]
10595 //sdci[5]=size[2]
10596 //sdci[6]=flip
10597 //sdci[7]=tile/combo
10598 //sdci[8]=polytype
10599 //sdci[9] bitmap as texture
10600 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10601 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10602 {
10603 Z_scripterrlog("bitmap->Triangle3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10604 return;
10605 }
10606 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10607 if ( refbmp == NULL ) return;
10608
10609 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10610
10611 if(!v_ptr)
10612 {
10613 al_trace("bitmap->Triangle3d: Vector pointer is null! Internal error. \n");
10614 return;
10615 }
10616
10617 std::vector<int32_t> &v = *v_ptr;
10618
10619 if(v.empty())
10620 return;
10621
10622 int32_t* pos = &v[0];
10623 int32_t* uv = &v[9];
10624 int32_t* col = &v[15];
10625 int32_t* size = &v[18];
10626
10627 int32_t w = size[0]; //magic numerical constants... yuck.
10628 int32_t h = size[1];
10629 int32_t flip = (sdci[6]/10000)&3;
10630 int32_t tile = sdci[7]/10000;
10631 int32_t polytype = sdci[8]/10000;
10632 int32_t quad_render_source = sdci[9];
10633 polytype = vbound(polytype, 0, 14);
10634
10635 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10636 {
10637 Z_message("bitmap->Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10638 return; //non power of two error
10639 }
10640
10641 int32_t tex_width = w*16;
10642 int32_t tex_height = h*16;
10643
10644 bool mustDestroyBmp = false;
10645 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10646
10647 if(!tex)
10648 {
10649 mustDestroyBmp = true;
10650 tex = create_bitmap_ex(8, tex_width, tex_height);
10651 clear_bitmap(tex);
10652 }
10653
10654 bool tex_is_bitmap = ( sdci[9] != 0 );
10655 BITMAP *bmptexture=NULL;
10656 if ( tex_is_bitmap )
10657 {
10658 bmptexture = resolveScriptingBitmap(quad_render_source);
10659 if ( !bmptexture )
10660 {
10661 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
10662 tex_is_bitmap = 0;
10663 }
10664 }
10665
10666 if ( !tex_is_bitmap )
10667 {
10668 if(tile > 0) // TILE
10669 {
10670 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10671 }
10672 else // COMBO
10673 {
10674 auto& c = GET_DRAWING_COMBO(vbound(abs(tile), 0, 0xffff));
10675 const int32_t tiletodraw = combo_tile(c, 0, 0);
10676 flip = flip ^ c.flip;
10677
10678 if(!(c.animflags & AF_EDITOR_ONLY))
10679 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10680 }
10681
10682 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10683 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10684 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10685
10686 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
10687 }
10688 else
10689 {
10690 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10691 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10692 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10693 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10694
10695 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10696 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10697 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10698
10699 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
10700
10701
10702 }
10703 if(mustDestroyBmp)
10704 destroy_bitmap(tex);
10705
10706 }
10707
10708
10709 bool is_layer_transparent(const mapscr& m, int32_t layer)
10710 {
10711 layer = vbound(layer, 0, 5);
10712 return m.layeropacity[layer] == 128;
10713 }
10714
10715 4338216 mapscr *getmapscreen(int32_t map_index, int32_t screen, int32_t layer) //returns NULL for invalid or non-existent layer
10716 {
10717 mapscr *base_scr;
10718 4338216 int32_t index = map_index*MAPSCRS+screen;
10719
10720
2/4
✓ Branch 0 taken 4338216 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4338216 times.
4338216 if((uint32_t)layer > 6 || (uint32_t)index >= TheMaps.size())
10721 return NULL;
10722
10723
2/2
✓ Branch 0 taken 3553310 times.
✓ Branch 1 taken 784906 times.
4338216 if(layer != 0)
10724 {
10725 784906 layer = layer - 1;
10726
10727 784906 base_scr=&(TheMaps[index]);
10728
10729
2/2
✓ Branch 0 taken 748179 times.
✓ Branch 1 taken 36727 times.
784906 if(base_scr->layermap[layer]==0)
10730 36727 return NULL;
10731
10732 748179 index=(base_scr->layermap[layer]-1)*MAPSCRS+base_scr->layerscreen[layer];
10733
10734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748179 times.
748179 if((uint32_t)index >= TheMaps.size()) // Might as well make sure
10735 return NULL;
10736 748179 }
10737
10738 4301489 return &(TheMaps[index]);
10739 4338216 }
10740
10741 636710856 static bool transparent_combo(int32_t id)
10742 {
10743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 636710856 times.
636710856 if(unsigned(id) >= MAXCOMBOS) return false;
10744 636710856 return bool(combobuf[id].animflags & AF_TRANSPARENT);
10745 636710856 }
10746
10747 191560 void draw_mapscr(BITMAP *b, const mapscr& m, int32_t x, int32_t y, bool transparent)
10748 {
10749
2/2
✓ Branch 0 taken 33714560 times.
✓ Branch 1 taken 191560 times.
33906120 for(int32_t i(0); i < 176; ++i)
10750 {
10751 33714560 const int32_t x2 = ((i&15)<<4) + x;
10752 33714560 const int32_t y2 = (i&0xF0) + y;
10753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33714560 times.
33714560 if(combobuf[m.data[i]].animflags & AF_EDITOR_ONLY) continue;
10754
10755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33714560 times.
33714560 if(transparent != transparent_combo(m.data[i]))
10756 {
10757 overcomboblocktranslucent(b, x2, y2, m.data[i], m.cset[i], 1, 1, 128);
10758 }
10759 else
10760 {
10761 33714560 overcomboblock(b, x2, y2, m.data[i], m.cset[i], 1, 1);
10762 }
10763 33714560 }
10764 191560 }
10765
10766 void draw_map_solidity(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10767 {
10768 BITMAP* square = create_bitmap_ex(8,16,16);
10769
10770 for(int32_t i(0); i < 176; ++i)
10771 {
10772 const int32_t x2 = ((i&15)<<4) + x;
10773 const int32_t y2 = (i&0xF0) + y;
10774 //Blit the palette index of the solidity value.
10775 clear_to_color(square,(combobuf[m.data[i]].walk&15));
10776 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10777 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10778 }
10779 destroy_bitmap(square);
10780 }
10781
10782 void do_bmpdrawscreen_solidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10783 {
10784 //sdci[1]=layer
10785 //sdci[2]=map
10786 //sdci[3]=screen
10787 //sdci[4]=x
10788 //sdci[5]=y
10789 //sdci[6]=rotation
10790 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10791
10792 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10793 if ( refbmp == NULL ) return;
10794
10795 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10796
10797 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10798 int32_t screen = sdci[3]/10000;
10799 int32_t x = sdci[4]/10000;
10800 int32_t y = sdci[5]/10000;
10801 int32_t x1 = x + xoffset;
10802 int32_t y1 = y + yoffset;
10803 int32_t rotation = sdci[6]/10000;
10804 uint32_t index = (uint32_t)map_screen_index(map, screen);
10805
10806 if(index >= TheMaps.size())
10807 {
10808 al_trace("DrawScreen: invalid map or screen index. \n");
10809 return;
10810 }
10811
10812 const mapscr & m = TheMaps[index];
10813
10814
10815 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10816 if ( refbmp == NULL ) return;
10817
10818 if(rotation != 0)
10819 b = script_drawing_commands.AquireSubBitmap(256, 176);
10820
10821 //draw layer 0
10822 draw_map_solidity(b, m, x1, y1);
10823 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10824 {
10825 for(int32_t i(0); i < 6; ++i)
10826 {
10827 if(m.layermap[i] == 0) continue;
10828
10829 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10830
10831 if(layer_screen_index >= TheMaps.size())
10832 continue;
10833
10834 //draw valid layers
10835 draw_map_solidity(b, TheMaps[ layer_screen_index ], x1, y1);
10836 }
10837 }
10838
10839 if(rotation != 0) // rotate
10840 {
10841 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10842 script_drawing_commands.ReleaseSubBitmap(b);
10843 }
10844 }
10845
10846 void draw_map_solid(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10847 {
10848 BITMAP* square = create_bitmap_ex(8,16,16);
10849 BITMAP* subsquare = create_bitmap_ex(8,16,16);
10850 clear_to_color(subsquare,1);
10851
10852 for(int32_t i(0); i < 176; ++i)
10853 {
10854 const int32_t x2 = ((i&15)<<4) + x;
10855 const int32_t y2 = (i&0xF0) + y;
10856 //Blit the palette index of the solidity value.
10857 clear_bitmap(square);
10858 int32_t sol = (combobuf[m.data[i]].walk);
10859 if ( sol & 1 )
10860 {
10861 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
10862 }
10863 if ( sol & 2 )
10864 {
10865 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
10866 }
10867 if ( sol & 4 )
10868 {
10869 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
10870 }
10871 if ( sol &8 ) {
10872 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
10873 }
10874
10875 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10876 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10877 }
10878 destroy_bitmap(square);
10879 destroy_bitmap(subsquare);
10880 }
10881
10882 void do_bmpdrawscreen_solidr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10883 {
10884 //sdci[1]=layer
10885 //sdci[2]=map
10886 //sdci[3]=screen
10887 //sdci[4]=x
10888 //sdci[5]=y
10889 //sdci[6]=rotation
10890 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10891
10892 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10893 if ( refbmp == NULL ) return;
10894
10895 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10896
10897 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10898 int32_t screen = sdci[3]/10000;
10899 int32_t x = sdci[4]/10000;
10900 int32_t y = sdci[5]/10000;
10901 int32_t x1 = x + xoffset;
10902 int32_t y1 = y + yoffset;
10903 int32_t rotation = sdci[6]/10000;
10904
10905 uint32_t index = (uint32_t)map_screen_index(map, screen);
10906
10907 if(index >= TheMaps.size())
10908 {
10909 al_trace("DrawScreen: invalid map or screen index. \n");
10910 return;
10911 }
10912
10913 const mapscr & m = TheMaps[index];
10914
10915
10916 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10917 if ( refbmp == NULL ) return;
10918
10919 if(rotation != 0)
10920 b = script_drawing_commands.AquireSubBitmap(256, 176);
10921
10922 //draw layer 0
10923 draw_map_solid(b, m, x1, y1);
10924
10925 for(int32_t i(0); i < 6; ++i) //This one doesn't need the QR; it works just fine.
10926 {
10927 if(m.layermap[i] == 0) continue;
10928
10929 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10930
10931 if(layer_screen_index >= TheMaps.size())
10932 continue;
10933
10934 //draw valid layers
10935 draw_map_solid(b, TheMaps[ layer_screen_index ], x1, y1);
10936 }
10937
10938 if(rotation != 0) // rotate
10939 {
10940 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10941 script_drawing_commands.ReleaseSubBitmap(b);
10942 }
10943 }
10944
10945 1024 void draw_map_cflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10946 {
10947 1024 BITMAP* square = create_bitmap_ex(8,16,16);
10948
10949
2/2
✓ Branch 0 taken 180224 times.
✓ Branch 1 taken 1024 times.
181248 for(int32_t i(0); i < 176; ++i)
10950 {
10951 180224 const int32_t x2 = ((i&15)<<4) + x;
10952 180224 const int32_t y2 = (i&0xF0) + y;
10953 //Blit the palette index of the solidity value.
10954 180224 clear_to_color(square,m.sflag[i]);
10955
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180224 times.
180224 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10956 180224 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10957 180224 }
10958 1024 destroy_bitmap(square);
10959 1024 }
10960
10961 1024 void do_bmpdrawscreen_cflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10962 {
10963 //sdci[1]=layer
10964 //sdci[2]=map
10965 //sdci[3]=screen
10966 //sdci[4]=x
10967 //sdci[5]=y
10968 //sdci[6]=rotation
10969 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10970
10971 1024 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10972
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10973
10974
2/4
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1024 times.
✗ Branch 3 not taken.
1024 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10975
10976 1024 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10977 1024 int32_t screen = sdci[3]/10000;
10978 1024 int32_t x = sdci[4]/10000;
10979 1024 int32_t y = sdci[5]/10000;
10980 1024 int32_t x1 = x + xoffset;
10981 1024 int32_t y1 = y + yoffset;
10982 1024 int32_t rotation = sdci[6]/10000;
10983
10984 1024 uint32_t index = (uint32_t)map_screen_index(map, screen);
10985
10986
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024 times.
1024 if(index >= TheMaps.size())
10987 {
10988 al_trace("DrawScreen: invalid map or screen index. \n");
10989 return;
10990 }
10991
10992 1024 const mapscr & m = TheMaps[index];
10993
10994
10995 1024 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
10996
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10997
10998
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0)
10999 b = script_drawing_commands.AquireSubBitmap(256, 176);
11000
11001 //draw layer 0
11002 1024 draw_map_cflag(b, m, x1, y1);
11003
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11004 {
11005 for(int32_t i(0); i < 6; ++i)
11006 {
11007 if(m.layermap[i] == 0) continue;
11008
11009 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11010
11011 if(layer_screen_index >= TheMaps.size())
11012 continue;
11013
11014 //draw valid layers
11015 draw_map_cflag(b, TheMaps[ layer_screen_index ], x1, y1);
11016 }
11017 }
11018
11019
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0) // rotate
11020 {
11021 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11022 script_drawing_commands.ReleaseSubBitmap(b);
11023 }
11024 1024 }
11025
11026
11027 void draw_map_combotype(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
11028 {
11029 BITMAP* square = create_bitmap_ex(8,16,16);
11030
11031 for(int32_t i(0); i < 176; ++i)
11032 {
11033 const int32_t x2 = ((i&15)<<4) + x;
11034 const int32_t y2 = (i&0xF0) + y;
11035 //Blit the palette index of the solidity value.
11036 clear_to_color(square,(combobuf[m.data[i]].type));
11037 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
11038 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
11039 }
11040 destroy_bitmap(square);
11041 }
11042
11043 void do_bmpdrawscreen_ctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11044 {
11045 //sdci[1]=layer
11046 //sdci[2]=map
11047 //sdci[3]=screen
11048 //sdci[4]=x
11049 //sdci[5]=y
11050 //sdci[6]=rotation
11051 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11052
11053 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11054 if ( refbmp == NULL ) return;
11055
11056 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11057
11058 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11059 int32_t screen = sdci[3]/10000;
11060 int32_t x = sdci[4]/10000;
11061 int32_t y = sdci[5]/10000;
11062 int32_t x1 = x + xoffset;
11063 int32_t y1 = y + yoffset;
11064 int32_t rotation = sdci[6]/10000;
11065
11066 uint32_t index = (uint32_t)map_screen_index(map, screen);
11067
11068 if(index >= TheMaps.size())
11069 {
11070 al_trace("DrawScreen: invalid map or screen index. \n");
11071 return;
11072 }
11073
11074 const mapscr & m = TheMaps[index];
11075
11076
11077 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11078 if ( refbmp == NULL ) return;
11079
11080 if(rotation != 0)
11081 b = script_drawing_commands.AquireSubBitmap(256, 176);
11082
11083 //draw layer 0
11084 draw_map_combotype(b, m, x1, y1);
11085
11086 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11087 {
11088 for(int32_t i(0); i < 6; ++i)
11089 {
11090 if(m.layermap[i] == 0) continue;
11091
11092 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11093
11094 if(layer_screen_index >= TheMaps.size())
11095 continue;
11096
11097 //draw valid layers
11098 draw_map_combotype(b, TheMaps[ layer_screen_index ], x1, y1);
11099 }
11100 }
11101
11102 if(rotation != 0) // rotate
11103 {
11104 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11105 script_drawing_commands.ReleaseSubBitmap(b);
11106 }
11107 }
11108
11109
11110 void draw_map_comboiflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
11111 {
11112 BITMAP* square = create_bitmap_ex(8,16,16);
11113
11114 for(int32_t i(0); i < 176; ++i)
11115 {
11116 const int32_t x2 = ((i&15)<<4) + x;
11117 const int32_t y2 = (i&0xF0) + y;
11118 //Blit the palette index of the solidity value.
11119 clear_to_color(square,(combobuf[m.data[i]].flag));
11120 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
11121 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
11122 }
11123 destroy_bitmap(square);
11124 }
11125
11126 void do_bmpdrawscreen_ciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11127 {
11128 //sdci[1]=layer
11129 //sdci[2]=map
11130 //sdci[3]=screen
11131 //sdci[4]=x
11132 //sdci[5]=y
11133 //sdci[6]=rotation
11134 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11135
11136 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11137 if ( refbmp == NULL ) return;
11138
11139 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11140
11141 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11142 int32_t screen = sdci[3]/10000;
11143 int32_t x = sdci[4]/10000;
11144 int32_t y = sdci[5]/10000;
11145 int32_t x1 = x + xoffset;
11146 int32_t y1 = y + yoffset;
11147 int32_t rotation = sdci[6]/10000;
11148
11149 uint32_t index = (uint32_t)map_screen_index(map, screen);
11150
11151 if(index >= TheMaps.size())
11152 {
11153 al_trace("DrawScreen: invalid map or screen index. \n");
11154 return;
11155 }
11156
11157 const mapscr & m = TheMaps[index];
11158
11159
11160 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11161 if ( refbmp == NULL ) return;
11162
11163 if(rotation != 0)
11164 b = script_drawing_commands.AquireSubBitmap(256, 176);
11165
11166 //draw layer 0
11167 draw_map_comboiflag(b, m, x1, y1);
11168
11169 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11170 {
11171 for(int32_t i(0); i < 6; ++i)
11172 {
11173 if(m.layermap[i] == 0) continue;
11174
11175 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11176
11177 if(layer_screen_index >= TheMaps.size())
11178 continue;
11179
11180 //draw valid layers
11181 draw_map_comboiflag(b, TheMaps[ layer_screen_index ], x1, y1);
11182 }
11183 }
11184
11185 if(rotation != 0) // rotate
11186 {
11187 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11188 script_drawing_commands.ReleaseSubBitmap(b);
11189 }
11190 }
11191
11192 4337043 void do_drawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11193 {
11194 //sdci[1]=layer
11195 //sdci[2]=map
11196 //sdci[3]=screen
11197 //sdci[4]=layer
11198 //sdci[5]=x
11199 //sdci[6]=y
11200 //sdci[7]=rotation
11201 //sdci[8]=opacity
11202
11203 4337043 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11204 4337043 int32_t screen = sdci[3]/10000;
11205 4337043 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11206 4337043 int32_t x = sdci[5]/10000;
11207 4337043 int32_t y = sdci[6]/10000;
11208 4337043 int32_t x1 = x + xoffset;
11209 4337043 int32_t y1 = y + yoffset;
11210 4337043 int32_t rotation = sdci[7]/10000;
11211 4337043 int32_t opacity = sdci[8]/10000;
11212
11213 4337043 uint32_t index = (uint32_t)map_screen_index(map, screen);
11214 4337043 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11215
11216
2/2
✓ Branch 0 taken 4300322 times.
✓ Branch 1 taken 36721 times.
4337043 if(!m) //no need to log it.
11217 36721 return;
11218
11219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4300322 times.
4300322 if(index >= TheMaps.size())
11220 {
11221 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11222 return;
11223 }
11224
11225 4300322 const mapscr & l = *m;
11226
11227 4300322 BITMAP* b = bmp;
11228
11229
1/2
✓ Branch 0 taken 4300322 times.
✗ Branch 1 not taken.
4300322 if(rotation != 0)
11230 b = script_drawing_commands.AquireSubBitmap(256, 176);
11231
11232
11233 4300322 const int32_t maxX = isOffScreen ? 512 : 256;
11234
2/2
✓ Branch 0 taken 4280939 times.
✓ Branch 1 taken 19383 times.
4300322 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11235 4300322 bool transparent = opacity <= 128;
11236
11237
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4300322 times.
4300322 if(rotation != 0) // rotate
11238 {
11239 draw_mapscr(b, l, x1, y1, transparent);
11240
11241 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11242 script_drawing_commands.ReleaseSubBitmap(b);
11243 }
11244 else
11245 {
11246
2/2
✓ Branch 0 taken 756856672 times.
✓ Branch 1 taken 4300322 times.
761156994 for(int32_t i(0); i < 176; ++i)
11247 {
11248 756856672 const int32_t x2 = ((i&15)<<4) + x1;
11249 756856672 const int32_t y2 = (i&0xF0) + y1;
11250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 756856672 times.
756856672 if(combobuf[l.data[i]].animflags & AF_EDITOR_ONLY) continue;
11251
11252
7/8
✓ Branch 0 taken 666352038 times.
✓ Branch 1 taken 90504634 times.
✓ Branch 2 taken 666352038 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 611946646 times.
✓ Branch 5 taken 54405392 times.
✓ Branch 6 taken 9155742 times.
✓ Branch 7 taken 602790904 times.
756856672 if(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY) //in clipping rect
11253 {
11254
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 602790904 times.
602790904 if(opacity < 128 != transparent_combo(l.data[i]))
11255 {
11256 overcomboblocktranslucent(b, x2, y2, l.data[i], l.cset[i], 1, 1, 128);
11257 }
11258 else
11259 {
11260 602790904 overcomboblock(b, x2, y2, l.data[i], l.cset[i], 1, 1);
11261 }
11262 602790904 }
11263 756856672 }
11264 }
11265
11266 //putscr
11267 4337043 }
11268
11269
11270
11271 50406 void do_drawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11272 {
11273 //sdci[1]=layer
11274 //sdci[2]=map
11275 //sdci[3]=screen
11276 //sdci[4]=x
11277 //sdci[5]=y
11278 //sdci[6]=rotation
11279
11280 50406 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11281 50406 int32_t screen = sdci[3]/10000;
11282 50406 int32_t x = sdci[4]/10000;
11283 50406 int32_t y = sdci[5]/10000;
11284 50406 int32_t x1 = x + xoffset;
11285 50406 int32_t y1 = y + yoffset;
11286 50406 int32_t rotation = sdci[6]/10000;
11287
11288 50406 uint32_t index = (uint32_t)map_screen_index(map, screen);
11289
11290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(index >= TheMaps.size())
11291 {
11292 al_trace("DrawScreen: invalid map or screen index. \n");
11293 return;
11294 }
11295
11296 50406 const mapscr & m = TheMaps[index];
11297
11298
11299 50406 BITMAP* b = bmp;
11300
11301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0)
11302 b = script_drawing_commands.AquireSubBitmap(256, 176);
11303
11304 //draw layer 0
11305 50406 draw_mapscr(b, m, x1, y1, false);
11306
11307
2/2
✓ Branch 0 taken 50406 times.
✓ Branch 1 taken 302436 times.
352842 for(int32_t i(0); i < 6; ++i)
11308 {
11309
2/2
✓ Branch 0 taken 137944 times.
✓ Branch 1 taken 164492 times.
302436 if(m.layermap[i] == 0) continue;
11310
11311 137944 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11312
11313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137944 times.
137944 if(layer_screen_index >= TheMaps.size())
11314 continue;
11315
11316 137944 bool trans = m.layeropacity[i] == 128;
11317
11318 //draw valid layers
11319 137944 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11320 137944 }
11321
11322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0) // rotate
11323 {
11324 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11325 script_drawing_commands.ReleaseSubBitmap(b);
11326 }
11327 50406 }
11328
11329
11330 1173 void do_bmpdrawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11331 {
11332 //sdci[1]=layer
11333 //sdci[2]=map
11334 //sdci[3]=screen
11335 //sdci[4]=layer
11336 //sdci[5]=x
11337 //sdci[6]=y
11338 //sdci[7]=rotation
11339 //[8] noclip
11340 //sdci[9]=opacity
11341 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11342
11343 1173 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11344
1/2
✓ Branch 0 taken 1173 times.
✗ Branch 1 not taken.
1173 if ( refbmp == NULL ) return;
11345
11346 1173 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11347 1173 int32_t screen = sdci[3]/10000;
11348 1173 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11349 1173 int32_t x = sdci[5]/10000;
11350 1173 int32_t y = sdci[6]/10000;
11351 1173 int32_t rotation = sdci[7]/10000;
11352
11353 1173 byte noclip = 0;//(sdci[8]!=0);
11354 1173 int32_t opacity = sdci[8]/10000;
11355 1173 uint32_t index = (uint32_t)map_screen_index(map, screen);
11356 1173 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11357
11358
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 6 times.
1173 if(!m) //no need to log it.
11359 6 return;
11360
11361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(index >= TheMaps.size())
11362 {
11363 Z_scripterrlog("DrawLayer: invalid map index \"%i\". Map count is %zu.\n", index, TheMaps.size());
11364 return;
11365 }
11366
11367 1167 const mapscr & l = *m;
11368
11369 1167 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11370
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if ( refbmp == NULL ) return;
11371
2/4
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1167 times.
✗ Branch 3 not taken.
1167 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11372
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if(rotation != 0)
11373 b = script_drawing_commands.AquireSubBitmap(256, 176);
11374
11375
11376 1167 const int32_t maxX = isOffScreen ? 512 : 256;
11377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11378 1167 bool transparent = opacity <= 128;
11379
11380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(rotation != 0) // rotate
11381 {
11382 draw_mapscr(b, l, x, y, transparent);
11383
11384 rotate_sprite(refbmp, b, x, y, degrees_to_fixed(rotation));
11385 script_drawing_commands.ReleaseSubBitmap(b);
11386 }
11387 else
11388 {
11389
2/2
✓ Branch 0 taken 205392 times.
✓ Branch 1 taken 1167 times.
206559 for(int32_t i(0); i < 176; ++i)
11390 {
11391 205392 const int32_t x2 = ((i&15)<<4) + x;
11392 205392 const int32_t y2 = (i&0xF0) + y;
11393
11394 //if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11395 {
11396 205392 auto& c = GET_DRAWING_COMBO(l.data[i]);
11397
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205392 times.
205392 if(c.animflags & AF_EDITOR_ONLY) continue;
11398 205392 const int32_t tile = combo_tile(c, x2, y2);
11399
11400
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205392 times.
205392 if(opacity < 128 != transparent_combo(l.data[i]))
11401 overtiletranslucent16(refbmp, tile, x2, y2, l.cset[i], c.flip, opacity);
11402 else
11403 205392 overtile16(refbmp, tile, x2, y2, l.cset[i], c.flip);
11404
11405 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
11406 }
11407 205392 }
11408 }
11409
11410 //putscr
11411 1173 }
11412
11413
11414
11415 1092 void do_bmpdrawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11416 {
11417 //sdci[1]=layer
11418 //sdci[2]=map
11419 //sdci[3]=screen
11420 //sdci[4]=x
11421 //sdci[5]=y
11422 //sdci[6]=rotation
11423 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11424
11425 1092 BITMAP *refbmp = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11426
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if ( refbmp == NULL ) return;
11427
11428
2/4
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1092 times.
1092 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11429
11430 1092 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11431 1092 int32_t screen = sdci[3]/10000;
11432 1092 int32_t x = sdci[4]/10000;
11433 1092 int32_t y = sdci[5]/10000;
11434 1092 int32_t x1 = x + xoffset;
11435 1092 int32_t y1 = y + yoffset;
11436 1092 int32_t rotation = sdci[6]/10000;
11437
11438 1092 uint32_t index = (uint32_t)map_screen_index(map, screen);
11439
11440
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if(index >= TheMaps.size())
11441 {
11442 al_trace("DrawScreen: invalid map or screen index. \n");
11443 return;
11444 }
11445
11446 1092 const mapscr & m = TheMaps[index];
11447
11448
11449 1092 BITMAP* b = resolveScriptingBitmap(sdci[DRAWCMD_BMP_TARGET]);
11450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if ( refbmp == NULL ) return;
11451
11452
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0)
11453 b = script_drawing_commands.AquireSubBitmap(256, 176);
11454
11455 //draw layer 0
11456 1092 draw_mapscr(b, m, x1, y1, false);
11457
11458
2/2
✓ Branch 0 taken 1092 times.
✓ Branch 1 taken 6552 times.
7644 for(int32_t i(0); i < 6; ++i)
11459 {
11460
2/2
✓ Branch 0 taken 2118 times.
✓ Branch 1 taken 4434 times.
6552 if(m.layermap[i] == 0) continue;
11461
11462 2118 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11463
11464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2118 times.
2118 if(layer_screen_index >= TheMaps.size())
11465 continue;
11466
11467 2118 bool trans = m.layeropacity[i] == 128;
11468
11469 //draw valid layers
11470 2118 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11471 2118 }
11472
11473
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0) // rotate
11474 {
11475 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11476 script_drawing_commands.ReleaseSubBitmap(b);
11477 }
11478 1092 }
11479
11480 void do_bmpdrawlayersolidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11481 {
11482 //sdci[1]=layer
11483 //sdci[2]=map
11484 //sdci[3]=screen
11485 //sdci[4]=layer
11486 //sdci[5]=x
11487 //sdci[6]=y
11488 //sdci[7]=rotation
11489 //sdci[8]=bool noclip
11490 //sdci[9] == opacity
11491
11492 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11493 int32_t screen = sdci[3]/10000;
11494 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11495 int32_t x = sdci[5]/10000;
11496 int32_t y = sdci[6]/10000;
11497 int32_t x1 = x + xoffset;
11498 int32_t y1 = y + yoffset;
11499 int32_t rotation = sdci[7]/10000;
11500 byte noclip = (sdci[8]!=0);
11501 int32_t opacity = sdci[9]/10000;
11502
11503 uint32_t index = (uint32_t)map_screen_index(map, screen);
11504 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11505
11506 if(!m) //no need to log it.
11507 return;
11508
11509 if(index >= TheMaps.size())
11510 {
11511 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11512 return;
11513 }
11514
11515 const mapscr & l = *m;
11516
11517 BITMAP* b = bmp;
11518
11519 if(rotation != 0)
11520 b = script_drawing_commands.AquireSubBitmap(256, 176);
11521
11522
11523 const int32_t maxX = isOffScreen ? 512 : 256;
11524 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11525 bool transparent = opacity <= 128;
11526
11527 if(rotation != 0) // rotate
11528 {
11529 draw_map_solid(b, l, x1, y1);
11530
11531 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11532 script_drawing_commands.ReleaseSubBitmap(b);
11533 }
11534 else
11535 {
11536 BITMAP* square = create_bitmap_ex(8,16,16);
11537 BITMAP* subsquare = create_bitmap_ex(8,16,16);
11538 clear_to_color(subsquare,1);
11539 for(int32_t i(0); i < 176; ++i)
11540 {
11541 const int32_t x2 = ((i&15)<<4) + x1;
11542 const int32_t y2 = (i&0xF0) + y1;
11543
11544 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11545 {
11546 int32_t sol = (combobuf[l.data[i]].walk);
11547
11548 if ( sol & 1 )
11549 {
11550 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
11551 }
11552 if ( sol & 2 )
11553 {
11554 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
11555 }
11556 if ( sol & 4 )
11557 {
11558 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
11559 }
11560 if ( sol &8 ) {
11561 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
11562 }
11563
11564 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11565 }
11566 }
11567 destroy_bitmap(square);
11568 destroy_bitmap(subsquare);
11569 }
11570
11571 //putscr
11572 }
11573
11574 void do_bmpdrawlayersolidityr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11575 {
11576 //sdci[1]=layer
11577 //sdci[2]=map
11578 //sdci[3]=screen
11579 //sdci[4]=layer
11580 //sdci[5]=x
11581 //sdci[6]=y
11582 //sdci[7]=rotation
11583 //[8] noclip
11584 //sdci[9]=opacity
11585
11586
11587 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11588 int32_t screen = sdci[3]/10000;
11589 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11590 int32_t x = sdci[5]/10000;
11591 int32_t y = sdci[6]/10000;
11592 int32_t x1 = x + xoffset;
11593 int32_t y1 = y + yoffset;
11594 int32_t rotation = sdci[7]/10000;
11595 byte noclip = (sdci[8]!=0);
11596 int32_t opacity = sdci[9]/10000;
11597
11598 uint32_t index = (uint32_t)map_screen_index(map, screen);
11599 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11600
11601 if(!m) //no need to log it.
11602 return;
11603
11604 if(index >= TheMaps.size())
11605 {
11606 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11607 return;
11608 }
11609
11610 const mapscr & l = *m;
11611
11612 BITMAP* b = bmp;
11613
11614 if(rotation != 0)
11615 b = script_drawing_commands.AquireSubBitmap(256, 176);
11616
11617
11618 const int32_t maxX = isOffScreen ? 512 : 256;
11619 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11620 bool transparent = opacity <= 128;
11621
11622 if(rotation != 0) // rotate
11623 {
11624 draw_map_solidity(b, l, x1, y1);
11625
11626 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11627 script_drawing_commands.ReleaseSubBitmap(b);
11628 }
11629 else
11630 {
11631 BITMAP* square = create_bitmap_ex(8,16,16);
11632 for(int32_t i(0); i < 176; ++i)
11633 {
11634 const int32_t x2 = ((i&15)<<4) + x1;
11635 const int32_t y2 = (i&0xF0) + y1;
11636
11637 if(noclip && (x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11638 {
11639 clear_to_color(square,(combobuf[l.data[i]].walk&15));
11640 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11641 }
11642 }
11643 destroy_bitmap(square);
11644 }
11645
11646 //putscr
11647 }
11648
11649 void do_bmpdrawlayercflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11650 {
11651 //sdci[1]=layer
11652 //sdci[2]=map
11653 //sdci[3]=screen
11654 //sdci[4]=layer
11655 //sdci[5]=x
11656 //sdci[6]=y
11657 //sdci[7]=rotation
11658 //[8] noclip
11659 //sdci[9]=opacity
11660
11661
11662 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11663 int32_t screen = sdci[3]/10000;
11664 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11665 int32_t x = sdci[5]/10000;
11666 int32_t y = sdci[6]/10000;
11667 int32_t x1 = x + xoffset;
11668 int32_t y1 = y + yoffset;
11669 int32_t rotation = sdci[7]/10000;
11670
11671 byte noclip = (sdci[8]!=0);
11672 int32_t opacity = sdci[9]/10000;
11673
11674 uint32_t index = (uint32_t)map_screen_index(map, screen);
11675 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11676
11677 if(!m) //no need to log it.
11678 return;
11679
11680 if(index >= TheMaps.size())
11681 {
11682 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11683 return;
11684 }
11685
11686 const mapscr & l = *m;
11687
11688 BITMAP* b = bmp;
11689
11690 if(rotation != 0)
11691 b = script_drawing_commands.AquireSubBitmap(256, 176);
11692
11693
11694 const int32_t maxX = isOffScreen ? 512 : 256;
11695 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11696 bool transparent = opacity <= 128;
11697
11698 if(rotation != 0) // rotate
11699 {
11700 draw_map_cflag(b, l, x1, y1);
11701
11702 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11703 script_drawing_commands.ReleaseSubBitmap(b);
11704 }
11705 else
11706 {
11707 BITMAP* square = create_bitmap_ex(8,16,16);
11708 for(int32_t i(0); i < 176; ++i)
11709 {
11710 const int32_t x2 = ((i&15)<<4) + x1;
11711 const int32_t y2 = (i&0xF0) + y1;
11712
11713 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11714 {
11715 clear_to_color(square,l.sflag[i]);
11716 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11717 }
11718 }
11719 destroy_bitmap(square);
11720 }
11721
11722 //putscr
11723 }
11724
11725 void do_bmpdrawlayerctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11726 {
11727 //sdci[1]=layer
11728 //sdci[2]=map
11729 //sdci[3]=screen
11730 //sdci[4]=layer
11731 //sdci[5]=x
11732 //sdci[6]=y
11733 //sdci[7]=rotation
11734 //[8] noclip
11735 //sdci[9]=opacity
11736
11737 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11738 int32_t screen = sdci[3]/10000;
11739 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11740 int32_t x = sdci[5]/10000;
11741 int32_t y = sdci[6]/10000;
11742 int32_t x1 = x + xoffset;
11743 int32_t y1 = y + yoffset;
11744 int32_t rotation = sdci[7]/10000;
11745
11746 byte noclip = (sdci[8]!=0);
11747 int32_t opacity = sdci[9]/10000;
11748 uint32_t index = (uint32_t)map_screen_index(map, screen);
11749 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11750
11751 if(!m) //no need to log it.
11752 return;
11753
11754 if(index >= TheMaps.size())
11755 {
11756 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11757 return;
11758 }
11759
11760 const mapscr & l = *m;
11761
11762 BITMAP* b = bmp;
11763
11764 if(rotation != 0)
11765 b = script_drawing_commands.AquireSubBitmap(256, 176);
11766
11767
11768 const int32_t maxX = isOffScreen ? 512 : 256;
11769 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11770 bool transparent = opacity <= 128;
11771
11772 if(rotation != 0) // rotate
11773 {
11774 draw_map_combotype(b, l, x1, y1);
11775
11776 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11777 script_drawing_commands.ReleaseSubBitmap(b);
11778 }
11779 else
11780 {
11781 BITMAP* square = create_bitmap_ex(8,16,16);
11782 for(int32_t i(0); i < 176; ++i)
11783 {
11784 const int32_t x2 = ((i&15)<<4) + x1;
11785 const int32_t y2 = (i&0xF0) + y1;
11786
11787 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11788 {
11789 clear_to_color(square,(combobuf[l.data[i]].type));
11790 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11791 }
11792 }
11793 destroy_bitmap(square);
11794 }
11795
11796 //putscr
11797 }
11798
11799 void do_bmpdrawlayerciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11800 {
11801 //sdci[1]=layer
11802 //sdci[2]=map
11803 //sdci[3]=screen
11804 //sdci[4]=layer
11805 //sdci[5]=x
11806 //sdci[6]=y
11807 //sdci[7]=rotation
11808 //[8] noclip
11809 //sdci[9]=opacity
11810
11811 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11812 int32_t screen = sdci[3]/10000;
11813 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11814 int32_t x = sdci[5]/10000;
11815 int32_t y = sdci[6]/10000;
11816 int32_t x1 = x + xoffset;
11817 int32_t y1 = y + yoffset;
11818 int32_t rotation = sdci[7]/10000;
11819 byte noclip = (sdci[8]!=0);
11820 int32_t opacity = sdci[9]/10000;
11821
11822 uint32_t index = (uint32_t)map_screen_index(map, screen);
11823 const mapscr* m = getmapscreen(map, screen, sourceLayer);
11824
11825 if(!m) //no need to log it.
11826 return;
11827
11828 if(index >= TheMaps.size())
11829 {
11830 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11831 return;
11832 }
11833
11834 const mapscr & l = *m;
11835
11836 BITMAP* b = bmp;
11837
11838 if(rotation != 0)
11839 b = script_drawing_commands.AquireSubBitmap(256, 176);
11840
11841
11842 const int32_t maxX = isOffScreen ? 512 : 256;
11843 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11844 bool transparent = opacity <= 128;
11845
11846 if(rotation != 0) // rotate
11847 {
11848 draw_map_comboiflag(b, l, x1, y1);
11849
11850 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11851 script_drawing_commands.ReleaseSubBitmap(b);
11852 }
11853 else
11854 {
11855 BITMAP* square = create_bitmap_ex(8,16,16);
11856 for(int32_t i(0); i < 176; ++i)
11857 {
11858 const int32_t x2 = ((i&15)<<4) + x1;
11859 const int32_t y2 = (i&0xF0) + y1;
11860
11861 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11862 {
11863 clear_to_color(square,(combobuf[l.data[i]].flag));
11864 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11865 }
11866 }
11867 destroy_bitmap(square);
11868 }
11869
11870 //putscr
11871 }
11872
11873
11874
11875 /////////////////////////////////////////////////////////
11876 // do primitives
11877 ////////////////////////////////////////////////////////
11878
11879 // Draw commands can vary in terms of the origin/coordinate system to draw as. This
11880 // is controlled via `DrawOrigin`. Previous to `DrawOrigin`, this always drew
11881 // relative to the playing field (except for offscreen bitmaps).
11882 401724869 void do_primitives(BITMAP *targetBitmap, int32_t type)
11883 {
11884 401724869 do_primitives(targetBitmap, type, 0, playing_field_offset);
11885 401724869 }
11886
11887 402928309 void do_primitives(BITMAP *targetBitmap, int32_t type, int32_t xoff, int32_t yoff)
11888 {
11889 402928309 color_map = &trans_table2;
11890
11891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 402928309 times.
402928309 if(type > 7)
11892 return;
11893
3/4
✓ Branch 0 taken 128170304 times.
✓ Branch 1 taken 274758005 times.
✓ Branch 2 taken 128170304 times.
✗ Branch 3 not taken.
402928309 if(type >= 0 && origin_scr->hidescriptlayers & (1<<type))
11894 return; //Script draws hidden for this layer
11895
2/2
✓ Branch 0 taken 3400629 times.
✓ Branch 1 taken 399527680 times.
402928309 if(!script_drawing_commands.is_dirty(type))
11896 399527680 return; //No draws to this layer
11897 //--script_drawing_commands[][] reference--
11898 //[][0]: type
11899 //[][1-16]: defined by type
11900 //...
11901 //[][DRAWCMD_BMP_TARGET]: bitmap pointer
11902 //[][DRAWCMD_CURRENT_TARGET]: current render target at time command is queued? unused?
11903
11904 3400629 const int32_t type_mul_10000 = type * 10000;
11905 3400629 const int32_t numDrawCommandsToProcess = script_drawing_commands.Count();
11906 3400629 FFCore.numscriptdraws = numDrawCommandsToProcess;
11907
11908
2/2
✓ Branch 0 taken 300645820 times.
✓ Branch 1 taken 3400629 times.
304046449 for (int i = 0; i < numDrawCommandsToProcess; i++)
11909 {
11910 300645820 auto& command = script_drawing_commands[i];
11911 300645820 int32_t *sdci = &script_drawing_commands[i][0];
11912
11913
2/2
✓ Branch 0 taken 200190475 times.
✓ Branch 1 taken 100455345 times.
300645820 if (sdci[1] != type_mul_10000)
11914 200190475 continue;
11915
11916 100455345 DrawOrigin draw_origin = command.draw_origin;
11917
11918 // get the correct render target, if set via Screen->SetRenderTarget
11919 // Note: This is a deprecated feature.
11920 100455345 BITMAP *bmp = zscriptDrawingRenderTarget->GetTargetBitmap(sdci[DRAWCMD_CURRENT_TARGET]);
11921 bool isTargetOffScreenBmp;
11922
11923
2/2
✓ Branch 0 taken 6431906 times.
✓ Branch 1 taken 94023439 times.
100455345 if(!bmp)
11924 {
11925 94023439 bmp = targetBitmap;
11926 94023439 isTargetOffScreenBmp = false;
11927 94023439 }
11928 else
11929 {
11930 // Render target was set to a internal bitmap (but not the screen bitmap).
11931 6431906 isTargetOffScreenBmp = true;
11932 6431906 draw_origin = DrawOrigin::Screen;
11933 }
11934
11935 100455345 current_target_bmp = bmp;
11936
11937 int xoffset, yoffset;
11938
1/2
✓ Branch 0 taken 100455345 times.
✗ Branch 1 not taken.
100455345 if (auto r = get_draw_origin_offset(draw_origin, command.draw_origin_target, xoff, yoff))
11939 {
11940 100455345 std::tie(xoffset, yoffset) = *r;
11941 100455345 }
11942 else
11943 {
11944 continue;
11945 }
11946
11947 100455345 secondary_draw_origin_xoff = 0;
11948 100455345 secondary_draw_origin_yoff = 0;
11949
2/2
✓ Branch 0 taken 100454985 times.
✓ Branch 1 taken 360 times.
100455345 if (command.secondary_draw_origin != DrawOrigin::Default)
11950 {
11951
1/2
✓ Branch 0 taken 360 times.
✗ Branch 1 not taken.
360 if (auto r = get_draw_origin_offset(command.secondary_draw_origin, command.secondary_draw_origin_target, xoff, yoff))
11952 {
11953 360 std::tie(secondary_draw_origin_xoff, secondary_draw_origin_yoff) = *r;
11954 360 }
11955 else
11956 {
11957 continue;
11958 }
11959 360 }
11960
11961
40/88
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 2499888 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1170321 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1850 times.
✓ Branch 7 taken 2351475 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 404879 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1576950 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2745108 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5303765 times.
✓ Branch 19 taken 22453186 times.
✓ Branch 20 taken 963845 times.
✓ Branch 21 taken 165084 times.
✓ Branch 22 taken 1598985 times.
✓ Branch 23 taken 163716 times.
✓ Branch 24 taken 9266 times.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✓ Branch 28 taken 1080 times.
✓ Branch 29 taken 933060 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 4337043 times.
✓ Branch 32 taken 50406 times.
✓ Branch 33 taken 7971 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 148823 times.
✗ Branch 36 not taken.
✓ Branch 37 taken 502 times.
✓ Branch 38 taken 144 times.
✗ Branch 39 not taken.
✓ Branch 40 taken 80910 times.
✓ Branch 41 taken 59816 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 824 times.
✗ Branch 44 not taken.
✓ Branch 45 taken 168443 times.
✓ Branch 46 taken 32636464 times.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✓ Branch 49 taken 865 times.
✓ Branch 50 taken 45504 times.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 56 not taken.
✓ Branch 57 taken 1173 times.
✓ Branch 58 taken 1092 times.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
✓ Branch 61 taken 1024 times.
✗ Branch 62 not taken.
✗ Branch 63 not taken.
✓ Branch 64 taken 265749 times.
✗ Branch 65 not taken.
✓ Branch 66 taken 113329 times.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✓ Branch 73 taken 325125 times.
✓ Branch 74 taken 3150 times.
✓ Branch 75 taken 34653 times.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 80 not taken.
✓ Branch 81 taken 19821648 times.
✗ Branch 82 not taken.
✓ Branch 83 taken 7323 times.
✗ Branch 84 not taken.
✓ Branch 85 taken 906 times.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
100455345 switch(sdci[0])
11962 {
11963 case RECTR:
11964 {
11965 2499888 do_rectr(bmp, sdci, xoffset, yoffset);
11966 }
11967 2499888 break;
11968 case FRAMER:
11969 {
11970 do_framer(bmp, sdci, xoffset, yoffset);
11971 }
11972 break;
11973
11974
11975 case CIRCLER:
11976 {
11977 1170321 do_circler(bmp, sdci, xoffset, yoffset);
11978 }
11979 1170321 break;
11980
11981 case ARCR:
11982 {
11983 do_arcr(bmp, sdci, xoffset, yoffset);
11984 }
11985 break;
11986
11987 case ELLIPSER:
11988 {
11989 1850 do_ellipser(bmp, sdci, xoffset, yoffset);
11990 }
11991 1850 break;
11992
11993 case LINER:
11994 {
11995 2351475 do_liner(bmp, sdci, xoffset, yoffset);
11996 }
11997 2351475 break;
11998
11999 case SPLINER:
12000 {
12001 do_spliner(bmp, sdci, xoffset, yoffset);
12002 }
12003 break;
12004
12005 case PUTPIXELR:
12006 {
12007 404879 do_putpixelr(bmp, sdci, xoffset, yoffset);
12008 }
12009 404879 break;
12010 case PIXELARRAYR:
12011 {
12012 do_putpixelsr(bmp, i, sdci, xoffset, yoffset);
12013 }
12014 break;
12015
12016 case TILEARRAYR:
12017 {
12018 do_fasttilesr(bmp, i, sdci, xoffset, yoffset);
12019 }
12020 break;
12021
12022 case LINESARRAY:
12023 {
12024 do_linesr(bmp, i, sdci, xoffset, yoffset);
12025 }
12026 break;
12027
12028 case COMBOARRAYR:
12029 {
12030 do_fastcombosr(bmp, i, sdci, xoffset, yoffset);
12031 }
12032 break;
12033
12034
12035
12036 case DRAWTILER:
12037 {
12038 1576950 do_drawtiler(bmp, sdci, xoffset, yoffset);
12039 }
12040 1576950 break;
12041
12042 case DRAWTILECLOAKEDR:
12043 {
12044 do_drawtilecloakedr(bmp, sdci, xoffset, yoffset);
12045 }
12046 break;
12047
12048 case DRAWCOMBOR:
12049 {
12050 2745108 do_drawcombor(bmp, sdci, xoffset, yoffset);
12051 }
12052 2745108 break;
12053
12054 case DRAWCOMBOCLOAKEDR:
12055 {
12056 do_drawcombocloakedr(bmp, sdci, xoffset, yoffset);
12057 }
12058 break;
12059
12060 case FASTTILER:
12061 {
12062 5303765 do_fasttiler(bmp, sdci, xoffset, yoffset);
12063 }
12064 5303765 break;
12065
12066 case FASTCOMBOR:
12067 {
12068 22453186 do_fastcombor(bmp, sdci, xoffset, yoffset);
12069 }
12070 22453186 break;
12071
12072 case DRAWCHARR:
12073 {
12074 963845 do_drawcharr(bmp, sdci, xoffset, yoffset);
12075 }
12076 963845 break;
12077
12078 case DRAWINTR:
12079 {
12080 165084 do_drawintr(bmp, sdci, xoffset, yoffset);
12081 }
12082 165084 break;
12083
12084 case DRAWSTRINGR:
12085 {
12086 1598985 do_drawstringr(bmp, i, sdci, xoffset, yoffset);
12087 }
12088 1598985 break;
12089
12090 case DRAWSTRINGR2:
12091 {
12092 163716 do_drawstringr2(bmp, i, sdci, xoffset, yoffset);
12093 }
12094 163716 break;
12095
12096 case QUADR:
12097 {
12098 9266 do_drawquadr(bmp, sdci, xoffset, yoffset);
12099 }
12100 9266 break;
12101
12102 case QUAD3DR:
12103 {
12104 do_drawquad3dr(bmp, i, sdci, xoffset, yoffset);
12105 }
12106 break;
12107
12108 case TRIANGLER:
12109 {
12110 do_drawtriangler(bmp, sdci, xoffset, yoffset);
12111 }
12112 break;
12113
12114 case TRIANGLE3DR:
12115 {
12116 do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset);
12117 }
12118 break;
12119
12120 case POLYGONR:
12121 {
12122 1080 do_polygonr(bmp, i, sdci, xoffset, yoffset);
12123 }
12124 1080 break;
12125
12126
12127 case BITMAPR:
12128 {
12129 933060 do_drawbitmapr(bmp, sdci, xoffset, yoffset);
12130 }
12131 933060 break;
12132
12133 case BITMAPEXR:
12134 {
12135 do_drawbitmapexr(bmp, sdci, xoffset, yoffset);
12136 }
12137 break;
12138
12139 case DRAWLAYERR:
12140 {
12141 4337043 do_drawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12142 }
12143 4337043 break;
12144
12145 case DRAWSCREENR:
12146 {
12147 50406 do_drawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12148 }
12149 50406 break;
12150
12151 7971 case BMPRECTR: bmp_do_rectr(bmp, sdci, xoffset, yoffset); break;
12152 case BMPFRAMER: bmp_do_framer(bmp, sdci, xoffset, yoffset); break;
12153 148823 case BMPCIRCLER: bmp_do_circler(bmp, sdci, xoffset, yoffset); break;
12154 case BMPARCR: bmp_do_arcr(bmp, sdci, xoffset, yoffset); break;
12155 502 case BMPELLIPSER: bmp_do_ellipser(bmp, sdci, xoffset, yoffset); break;
12156 144 case BMPLINER: bmp_do_liner(bmp, sdci, xoffset, yoffset); break;
12157 case BMPSPLINER: bmp_do_spliner(bmp, sdci, xoffset, yoffset); break;
12158 80910 case BMPPUTPIXELR: bmp_do_putpixelr(bmp, sdci, xoffset, yoffset); break;
12159 59816 case BMPDRAWTILER: bmp_do_drawtiler(bmp, sdci, xoffset, yoffset); break;
12160 case BMPDRAWTILECLOAKEDR: bmp_do_drawtilecloakedr(bmp, sdci, xoffset, yoffset); break;
12161 824 case BMPDRAWCOMBOR: bmp_do_drawcombor(bmp, sdci, xoffset, yoffset); break;
12162 case BMPDRAWCOMBOCLOAKEDR: bmp_do_drawcombocloakedr(bmp, sdci, xoffset, yoffset); break;
12163 168443 case BMPFASTTILER: bmp_do_fasttiler(bmp, sdci, xoffset, yoffset); break;
12164 32636464 case BMPFASTCOMBOR: bmp_do_fastcombor(bmp, sdci, xoffset, yoffset); break;
12165 case BMPDRAWCHARR: bmp_do_drawcharr(bmp, sdci, xoffset, yoffset); break;
12166 case BMPDRAWINTR: bmp_do_drawintr(bmp, sdci, xoffset, yoffset); break;
12167 865 case BMPDRAWSTRINGR: bmp_do_drawstringr(bmp, i, sdci, xoffset, yoffset); break;
12168 45504 case BMPDRAWSTRINGR2: bmp_do_drawstringr2(bmp, i, sdci, xoffset, yoffset); break;
12169 case BMPQUADR: bmp_do_drawquadr(bmp, sdci, xoffset, yoffset); break;
12170 case BMPQUAD3DR: bmp_do_drawquad3dr(bmp, i, sdci, xoffset, yoffset); break;
12171
12172 case BITMAPGETPIXEL: bmp_do_getpixelr(bmp, sdci, xoffset, yoffset); break;
12173 case BMPTRIANGLER: bmp_do_drawtriangler(bmp, sdci, xoffset, yoffset); break;
12174 case BMPTRIANGLE3DR: bmp_do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset); break;
12175 case BMPPOLYGONR: bmp_do_polygonr(bmp, i, sdci, xoffset, yoffset); break;
12176 1173 case BMPDRAWLAYERR: do_bmpdrawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12177 1092 case BMPDRAWSCREENR: do_bmpdrawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12178 case BMPDRAWSCREENSOLIDR: do_bmpdrawscreen_solidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12179 case BMPDRAWSCREENSOLID2R: do_bmpdrawscreen_solidr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12180 1024 case BMPDRAWSCREENCOMBOFR: do_bmpdrawscreen_cflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12181 case BMPDRAWSCREENCOMBOIR: do_bmpdrawscreen_ciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12182 case BMPDRAWSCREENCOMBOTR: do_bmpdrawscreen_ctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12183 265749 case BMPBLIT: bmp_do_drawbitmapexr(bmp, sdci, xoffset, yoffset); break;
12184 case BMPMODE7: bmp_do_mode7r(bmp, sdci, xoffset, yoffset); break;
12185 113329 case BMPBLITTO: bmp_do_blittor(bmp, sdci, xoffset, yoffset); break;
12186 case TILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, false, "TileBlit()"); break;
12187 case COMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, false); break;
12188 case BMPTILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, true, "TileBlit()"); break;
12189 case BMPCOMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, true); break;
12190 case READBITMAP: bmp_do_readr(bmp, i, sdci, xoffset, yoffset); break;
12191 case WRITEBITMAP: bmp_do_writer(bmp, i, sdci, xoffset, yoffset); break;
12192 325125 case CLEARBITMAP: bmp_do_clearr(bmp, sdci, xoffset, yoffset); break;
12193 3150 case BITMAPCLEARTOCOLOR: bmp_do_clearcolorr(bmp, sdci, xoffset, yoffset); break;
12194 34653 case REGENERATEBITMAP: bmp_do_regenr(bmp, sdci, xoffset, yoffset); break;
12195
12196 case BMPDRAWLAYERSOLIDR: do_bmpdrawlayersolidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12197 case BMPDRAWLAYERCFLAGR: do_bmpdrawlayercflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12198 case BMPDRAWLAYERCTYPER: do_bmpdrawlayerctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12199 case BMPDRAWLAYERCIFLAGR: do_bmpdrawlayerciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12200 case BMPDRAWLAYERSOLIDITYR: do_bmpdrawlayersolidityr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12201 19821648 case BMPWRITETILE: do_bmpwritetile(bmp, sdci, xoffset, yoffset); break;
12202 case BMPDITHER: do_bmpdither(bmp, sdci, xoffset, yoffset); break;
12203 7323 case BMPREPLCOLOR: do_bmpreplcol(bmp, sdci, xoffset, yoffset); break;
12204 case BMPSHIFTCOLOR: do_bmpshiftcol(bmp, sdci, xoffset, yoffset); break;
12205 906 case BMPMASKDRAW: do_bmpmaskdraw(bmp, sdci, xoffset, yoffset); break;
12206 case BMPMASKBLIT: do_bmpmaskblit(bmp, sdci, xoffset, yoffset); break;
12207
12208 // The following are special cases, in that the target bitmap is fixed (darkscr_bmp).
12209
12210 case DRAWLIGHT_CONE:
12211 {
12212 int32_t cx = sdci[2]/10000 + xoffset;
12213 int32_t cy = sdci[3]/10000 + yoffset;
12214 int32_t dir = sdci[4]/10000;
12215 int32_t length = sdci[5];
12216 int32_t transp_rad = sdci[6];
12217 int32_t dith_rad = sdci[7];
12218 int32_t dith_type = sdci[8];
12219 int32_t dith_arg = sdci[9];
12220
12221 if(length >= 0) length /= 10000;
12222 else length = game->get_light_rad()*2;
12223 if(!length) break;
12224 if(dir < 0) break;
12225 else dir = NORMAL_DIR(dir);
12226 if(transp_rad >= 0) transp_rad /= 10000;
12227 if(dith_rad >= 0) dith_rad /= 10000;
12228 if(dith_type >= 0) dith_type /= 10000;
12229 if(dith_arg >= 0) dith_arg /= 10000;
12230
12231 // Undo the inherit offset applied within the function. xoffset/yoffset handles for us here.
12232 cx += viewport.x;
12233 cy += viewport.y;
12234
12235 doDarkroomCone(cx,cy,length,dir,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
12236 }
12237 break;
12238
12239 case DRAWLIGHT_CIRCLE:
12240 case DRAWLIGHT_SQUARE:
12241 {
12242 int32_t cx = sdci[2]/10000 + xoffset;
12243 int32_t cy = sdci[3]/10000 + yoffset;
12244 int32_t radius = sdci[4];
12245 int32_t transp_rad = sdci[5];
12246 int32_t dith_rad = sdci[6];
12247 int32_t dith_type = sdci[7];
12248 int32_t dith_arg = sdci[8];
12249
12250 if(radius >= 0) radius /= 10000;
12251 else radius = game->get_light_rad();
12252 if(!radius) break;
12253 if(transp_rad >= 0) transp_rad /= 10000;
12254 if(dith_rad >= 0) dith_rad /= 10000;
12255 if(dith_type >= 0) dith_type /= 10000;
12256 if(dith_arg >= 0) dith_arg /= 10000;
12257
12258 // Undo the inherit offset applied within the function. xoffset/yoffset handles for us here.
12259 cx += viewport.x;
12260 cy += viewport.y;
12261
12262 if (sdci[0] == DRAWLIGHT_CIRCLE)
12263 doDarkroomCircle(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
12264 else
12265 doDarkroomSquare(cx,cy,radius,darkscr_bmp,nullptr,dith_rad,transp_rad,dith_type,dith_arg);
12266 }
12267 break;
12268 }
12269 100455345 }
12270
12271
12272 3400629 color_map=&trans_table;
12273 402928309 }
12274
12275 16248612 void CScriptDrawingCommands::Clear()
12276 {
12277 16248612 scb.update();
12278 16248612 dirty_layers.clear();
12279
2/2
✓ Branch 0 taken 11515773 times.
✓ Branch 1 taken 4732839 times.
16248612 if(commands.empty())
12280 11515773 return;
12281
12282 //only clear what was used.
12283 4732839 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12284 4732839 count = 0;
12285
12286 4732839 draw_container.Clear();
12287 16248612 }
12288 CScriptDrawingCommands* CScriptDrawingCommands::pop_commands()
12289 {
12290 CScriptDrawingCommands* ret = new CScriptDrawingCommands();
12291 if(commands.empty())
12292 return ret;
12293 ret->push_commands(this, false);
12294
12295 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12296 count = 0;
12297
12298 draw_container.Clear();
12299 return ret;
12300 }
12301 void CScriptDrawingCommands::push_commands(CScriptDrawingCommands* other, bool del)
12302 {
12303 commands.insert(commands.end(), other->commands.begin(), other->commands.end());
12304 count += other->count;
12305 if(del) delete other;
12306 }
12307
12308 150430 void do_script_draws(BITMAP *targetBitmap, mapscr* scr, int32_t xoff, int32_t yoff, bool hideLayer7)
12309 {
12310
2/2
✓ Branch 0 taken 149436 times.
✓ Branch 1 taken 994 times.
150430 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, xoff, yoff);
12311
2/2
✓ Branch 0 taken 148612 times.
✓ Branch 1 taken 1818 times.
150430 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, xoff, yoff);
12312 150430 do_primitives(targetBitmap, 0, xoff, yoff);
12313 150430 do_primitives(targetBitmap, 1, xoff, yoff);
12314
2/2
✓ Branch 0 taken 994 times.
✓ Branch 1 taken 149436 times.
150430 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, xoff, yoff);
12315
2/2
✓ Branch 0 taken 1818 times.
✓ Branch 1 taken 148612 times.
150430 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, xoff, yoff);
12316 150430 do_primitives(targetBitmap, 4, xoff, yoff);
12317 150430 do_primitives(targetBitmap, 5, xoff, yoff);
12318 150430 do_primitives(targetBitmap, 6, xoff, yoff);
12319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 150430 times.
150430 if(!hideLayer7) do_primitives(targetBitmap, 7, xoff, yoff);
12320 150430 }
12321